Beispiel #1
0
 public function formatMessage(MougrimLogger $logger, $level, $message, \Exception $throwable = null)
 {
     $prefix = '';
     $mdc = LoggerMDC::getMap();
     if ($this->logUserInfo) {
         foreach (['ip', 'userId', 'sessionId'] as $key) {
             $context = isset($mdc[$key]) ? $mdc[$key] : null;
             $context = LoggerRender::render($context);
             $prefix .= '[' . $context . ']';
             unset($mdc[$key]);
         }
     }
     $level = MougrimLogger::getLevelName($level);
     $formatted = date('Y-m-d H:i:s') . ' ' . $prefix . '[' . $level . '][' . $logger->getName() . ']';
     $ndcString = '';
     if ($ndcStack = LoggerNDC::getStack()) {
         $ndcString = implode(' ', $ndcStack);
     }
     $formatted .= '[' . $ndcString . ']';
     $mdcString = '';
     foreach ($mdc as $key => $context) {
         $mdcString .= $key . '=' . $context . ' ';
     }
     $formatted .= '[' . trim($mdcString) . ']';
     $formatted .= ' ' . LoggerRender::render($message);
     if ($throwable) {
         $formatted .= ' ' . LoggerRender::render($throwable);
     }
     return $formatted . PHP_EOL;
 }
Beispiel #2
0
 public function testConstruct()
 {
     $root = new Logger('root');
     $logger = new Logger('logger', $root);
     $this->assertSame('logger', $logger->getName());
     $this->assertTrue($root === $logger->getParent());
     $this->assertSame([], $logger->getAppenders());
     $this->assertTrue($logger->getAddictive());
 }
Beispiel #3
0
 public function formatMessage(Logger $logger, $level, $message, \Exception $throwable = null)
 {
     $formatted = $logger->getName() . ' [' . Logger::getLevelName($level) . '] ';
     if ($ndc = LoggerNDC::getStack()) {
         $formatted .= implode(' ', $ndc) . ' ';
     }
     if ($mdc = LoggerMDC::getMap()) {
         foreach ($mdc as $key => $context) {
             $formatted .= $key . '=' . $context . ' ';
         }
     }
     $formatted .= '- ' . LoggerRender::render($message);
     if ($throwable) {
         $formatted .= ' ' . LoggerRender::render($throwable);
     }
     return $formatted . PHP_EOL;
 }
Beispiel #4
0
 public function render(Logger $logger, $level, $message, \Exception $throwable = null)
 {
     return $this->format($logger->getName());
 }