diff --git a/Entity/LogEntry.php b/Entity/LogEntry.php index 07776ad..2a0fe06 100644 --- a/Entity/LogEntry.php +++ b/Entity/LogEntry.php @@ -1,9 +1,7 @@ id = $id; + return $this; } @@ -87,11 +87,13 @@ class LogEntry /** * @param mixed $message + * * @return LogEntry */ public function setMessage($message) { $this->message = $message; + return $this; } @@ -105,11 +107,13 @@ class LogEntry /** * @param mixed $context + * * @return LogEntry */ public function setContext($context) { $this->context = $context; + return $this; } @@ -123,11 +127,13 @@ class LogEntry /** * @param mixed $level + * * @return LogEntry */ public function setLevel($level) { $this->level = $level; + return $this; } @@ -141,11 +147,13 @@ class LogEntry /** * @param mixed $levelName + * * @return LogEntry */ public function setLevelName($levelName) { $this->levelName = $levelName; + return $this; } @@ -159,11 +167,13 @@ class LogEntry /** * @param mixed $channel + * * @return LogEntry */ public function setChannel($channel) { $this->channel = $channel; + return $this; } @@ -177,11 +187,13 @@ class LogEntry /** * @param mixed $createdAt + * * @return LogEntry */ public function setCreatedAt($createdAt) { $this->createdAt = $createdAt; + return $this; } -} \ No newline at end of file +} diff --git a/Service/LoggerService.php b/Service/LoggerService.php index 08e4393..640ddcf 100644 --- a/Service/LoggerService.php +++ b/Service/LoggerService.php @@ -1,11 +1,8 @@ 'DEBUG', - self::INFO => 'INFO', - self::NOTICE => 'NOTICE', - self::WARNING => 'WARNING', - self::ERROR => 'ERROR', - self::CRITICAL => 'CRITICAL', - self::ALERT => 'ALERT', + self::DEBUG => 'DEBUG', + self::INFO => 'INFO', + self::NOTICE => 'NOTICE', + self::WARNING => 'WARNING', + self::ERROR => 'ERROR', + self::CRITICAL => 'CRITICAL', + self::ALERT => 'ALERT', self::EMERGENCY => 'EMERGENCY', ); @@ -87,11 +84,12 @@ class LoggerService /** * LoggerService constructor. + * * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { - $this->name = ""; + $this->name = ''; $this->em = $em; } @@ -113,9 +111,9 @@ class LoggerService /** * Adds a log record. * - * @param int $level The logging level - * @param string $message The log message - * @param array $context The log context + * @param int $level The logging level + * @param string $message The log message + * @param array $context The log context * * @return bool Whether the record has been processed */ @@ -123,8 +121,8 @@ class LoggerService { $levelName = static::getLevelName($level); - if( $level > self::WARNING) { - $context += $this->automaticContext(); + if ($level > self::WARNING) { + $context = array_merge($context, $this->automaticContext()); } $logEntry = (new LogEntry()) @@ -138,11 +136,12 @@ class LoggerService $this->em->persist($logEntry); $this->em->flush(); - return true; + return $logEntry->getId(); } private function automaticContext() { + // filter the kernel classes and itself $classFilters = [ 'Ardent\LoggerBundle\Service\LoggerService', 'HttpKernel\Kernel', @@ -154,17 +153,18 @@ class LoggerService foreach ($backtraces as $trace) { $skip = false; foreach ($classFilters as $class) { - if(strpos($trace['class'], $class)) { + if (strpos($trace['class'], $class)) { $skip = true; } } - if($skip) { + if ($skip) { continue; } $context[] = "function[$traces]: ".$trace['function']; $context[] = "class[$traces]: ".$trace['class']; ++$traces; } + return $context; } @@ -179,7 +179,6 @@ class LoggerService ->orderBy('l.createdAt', 'DESC') ->setParameter(1, $level) ->setMaxResults($amount); - ; return $qb->getQuery()->getResult(); } @@ -187,7 +186,8 @@ class LoggerService /** * Gets the name of the logging level. * - * @param int $level + * @param int $level + * * @return string */ public static function getLevelName($level) @@ -209,11 +209,13 @@ class LoggerService /** * @param mixed $name + * * @return LoggerService */ public function setName($name) { $this->name = $name; + return $this; } -} \ No newline at end of file +}