Ejemplo n.º 1
0
 /**
  * 保存日志
  * @param string $logString 日志信息
  * @param string $level 日志级别
  */
 public function log($logString, $level = 'info')
 {
     $logger = new FileLogger($this->logDir . $this->logFile);
     $lineFormatter = new LineFormatter();
     $lineFormatter->setDateFormat('Y-m-d H:i:s');
     $logger->setFormatter($lineFormatter);
     $logger->log($logString, $this->log_level[$level]);
 }
Ejemplo n.º 2
0
 public function add($message, $type, $time, $context)
 {
     $debugbar = $this->_di['debugbar'];
     if (is_scalar($message) && $this->_formatter == 'syslog' && ($formatter = new Syslog())) {
         $message = $formatter->format($message, $type, $time, $context);
         $message = $message[1];
     } elseif (is_scalar($message) && $this->_formatter == 'line' && ($formatter = new Line())) {
         $message = $formatter->format($message, $type, $time, $context);
     } elseif (class_exists($this->_formatter) && $this->_formatter instanceof FormatterInterface) {
         $formatter = new $this->_formatter();
         $message = $formatter->format($message, $type, $time, $context);
     }
     if ($this->_aggregate) {
         /** @var MessagesCollector $message_collector */
         $message_collector = $debugbar->getCollector('messages');
         $message_collector->addMessage($message, $this->_levelMap[$type], true, $time);
     } else {
         $this->_logs[] = array('message' => $message, 'label' => $this->_levelMap[$type], 'time' => $time, 'is_string' => is_string($message), 'context' => $context);
     }
 }
Ejemplo n.º 3
0
 /**
  * Tests set/getFormat
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2012-09-17
  */
 public function testLoggerAdapterFileSetGetFormat()
 {
     $formatter = new Line();
     $format = '%type%|%date%|%message%';
     $formatter->setFormat($format);
     $actual = $formatter->getFormat();
     $expected = $format;
     $this->assertEquals($expected, $actual, 'set/getFormat does not correctly set/get the format');
 }
Ejemplo n.º 4
0
 public function format($message, $type, $timestamp, $context = null)
 {
     return parent::format($message, $type, $timestamp, $context);
 }