Pimcore\Logger::addLogger PHP Method

addLogger() public static method

public static addLogger ( $logger, boolean | false $reset = false )
$logger
$reset boolean | false
    public static function addLogger($logger, $reset = false)
    {
        if (!$logger instanceof \Zend_Log && !$logger instanceof \Psr\Log\LoggerInterface) {
            throw new \Exception("Logger must be either an instance of Zend_Log or needs to implement Psr\\Log\\LoggerInterface");
        }
        if ($reset) {
            self::$logger = [];
        }
        self::$logger[] = $logger;
        self::$enabled = true;
    }

Usage Example

Example #1
0
 /**
  * Initialize logging
  */
 protected function initializeLogging()
 {
     $logger = $this->getLogger();
     // hook logger into pimcore
     Logger::addLogger($logger);
     if ($this->output->isVerbose()) {
         Logger::setPriorities(["info", "notice", "warning", "error", "critical", "alert", "emergency"]);
     }
     // set all priorities
     if ($this->output->isDebug()) {
         Logger::setVerbosePriorities();
     }
 }