Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LoggingUtil.php
Go to the documentation of this file.
1 <?php
8 
9 use Monolog\Handler\StreamHandler;
10 use Monolog\Logger;
11 
13 {
19  private $loggers = [];
20 
26  private static $INSTANCE;
27 
33  public static function getInstance()
34  {
35  if (self::$INSTANCE == null) {
36  self::$INSTANCE = new LoggingUtil();
37  }
38 
39  return self::$INSTANCE;
40  }
41 
45  private function __construct()
46  {
47  // private constructor
48  }
49 
58  public function getLogger($clazz)
59  {
60  if ($clazz == null) {
61  throw new \Exception("You must pass a class to receive a logger");
62  }
63 
64  if (!array_key_exists($clazz, $this->loggers)) {
65  $logger = new MftfLogger($clazz);
66  $logger->pushHandler(new StreamHandler($this->getLoggingPath()));
67  $this->loggers[$clazz] = $logger;
68  }
69 
70  return $this->loggers[$clazz];
71  }
72 
78  public function getLoggingPath()
79  {
80  return TESTS_BP . DIRECTORY_SEPARATOR . "mftf.log";
81  }
82 }
$logger