*/ trait LoggerAwareTrait { private $logger; /** * Set a new logger * * @param LoggerInterface $logger */ public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } /** * Get the logger based on service manager * * @return \Psr\Log\LoggerInterface */ public function getLogger() { if ($this->logger instanceof LoggerInterface) { return $this->logger; } if ($this instanceof ServiceLocatorAwareInterface) { $logger = $this->getServiceLocator()->get(LoggerService::SERVICE_ID); } else { $logger = ServiceManager::getServiceManager()->get(LoggerService::SERVICE_ID); } return ($logger instanceof LoggerInterface) ? $logger : new NullLogger(); } // Helpers /** * Logs an emergency * * @param string $message * @param array $context */ public function logEmergency($message, $context = []) { $this->getLogger()->emergency($message, $context); } public function logAlert($message, $context = []) { $this->getLogger()->alert($message, $context); } public function logCritical($message, $context = []) { $this->getLogger()->critical($message, $context); } public function logError($message, $context = []) { $this->getLogger()->error($message, $context); } public function logWarning($message, $context = []) { $this->getLogger()->warning($message, $context); } public function logNotice($message, $context = []) { $this->getLogger()->notice($message, $context); } public function logInfo($message, $context = []) { $this->getLogger()->info($message, $context); } public function logDebug($message, $context = []) { $this->getLogger()->debug($message, $context); } }