Наследование: extends Enumeration
 /**
  * @param LogRecord $logRecord
  * @return string
  */
 public function format($logRecord)
 {
     $time = $logRecord->getTime();
     $result = $time->format('Y-m-d H:i:s') . ' [' . LogLevel::getName($logRecord->getLevel()) . '] ' . getmypid();
     $message = (string) $logRecord->getMessage();
     if ($message !== '') {
         $result .= ' | ' . str_replace("\n", "\n  ", $message);
     }
     return $result . PHP_EOL;
 }
Пример #2
0
 public function entry($message, $level = Logular\LogLevel::INFO, $variable = null)
 {
     if ($level < $this->minLogLevel) {
         return;
     }
     $params = [':level' => LogLevel::getText($level), ':message' => $message, ':pid' => getmypid()];
     try {
         $this->insert->execute($params);
     } catch (Exception $e) {
     }
 }
Пример #3
0
 function write_entries($entries)
 {
     echo "<table>";
     echo "<tr><th>Time</th><th>Type</th><th>Entity</th><th>Message</th><th>Judge host</th><th>User</th><th>IP</th></tr>";
     foreach ($entries as $entry) {
         echo "<tr>";
         echo "<td>" . format_date_compact($entry->time);
         echo "<td>" . htmlspecialchars(LogLevel::toString($entry->level));
         echo "<td>" . ($entry->entity_path ? "<a href=\"index.php" . htmlspecialchars($entry->entity_path) . "\">" . $entry->entity_path . "</a>" : "-");
         echo "<td>" . nl2br(htmlspecialchars($entry->message));
         echo "<td>" . ($entry->judge_host ? htmlspecialchars($entry->judge_host) : '-');
         echo "<td>" . ($entry->userid ? htmlspecialchars(User::by_id($entry->userid, false)->name_and_login()) : '-');
         echo "<td>" . ($entry->ip ? htmlspecialchars($entry->ip) : '-');
         echo "</tr>";
     }
     echo "</table>";
 }
Пример #4
0
 public function entry($message, $level = LogLevel::INFO, $variable = null)
 {
     if ($level < $this->minLogLevel) {
         throw new Exception('Log entry is below minimum level');
     }
     $timestamp = $this->getTimestamp();
     $level = LogLevel::getText($level);
     $message = "[{$level}] [{$timestamp}] {$message}";
     if (!is_null($variable) && $this->minLogLevel == LogLevel::DEBUG) {
         ob_start();
         var_dump($variable);
         $result = ob_get_clean();
         $traces = explode("\n", $result);
         $debugLevel = LogLevel::getText(LogLevel::DEBUG);
         $message .= PHP_EOL;
         foreach ($traces as $trace) {
             $trace = str_replace("\r", "", $trace);
             $message .= "[{$debugLevel}] [{$timestamp}] {$trace}" . PHP_EOL;
         }
     }
     return $message;
 }
Пример #5
0
 /**
  * @return BaseLogger
  **/
 public final function finest($message)
 {
     $this->log(LogLevel::finest(), $message);
     return $this;
 }
Пример #6
0
 /**
  * Creates a string representation
  *
  * @return  string
  */
 public function toString()
 {
     return sprintf('%s(%s @ %s, PID %d) {%s}%s', nameof($this), LogLevel::nameOf($this->level), date('r', $this->timestamp), $this->processId, null === ($context = $this->getContext()) ? '' : ' ' . $context->toString(), \xp::stringOf($this->arguments));
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function setLevel($level = LogLevel::INFO)
 {
     // check level
     LogLevel::getLevelCode($level);
     // set level
     $this->level = $level;
     return $this;
 }
Пример #8
0
 /**
  * Checks if the log level provided is a valid one according to the PSR-3
  * specification.
  *
  * @param string $level the level to check for validity
  */
 protected function isLevelAllowed($level)
 {
     return LogLevel::isValid($level);
 }
Пример #9
0
 /**
  * Configure this logger
  *
  * @param   util.Properties prop instance of a Properties object
  */
 public function configure($prop)
 {
     // Read all other properties
     $section = $prop->getFirstSection();
     do {
         $this->category[$section] = XPClass::forName($prop->readString($section, 'category', 'util.log.LogCategory'))->newInstance($section, $prop->readInteger($section, 'flags', LogLevel::ALL));
         // Configure appenders
         $appenders = $prop->readArray($section, 'appenders', array());
         // Go through all of the appenders, loading classes as necessary
         foreach ($appenders as $appender) {
             // Read levels (alternatively, for BC, read "flags" setting)
             $levels = $prop->readArray($section, 'appender.' . $appender . '.levels');
             if (!empty($levels)) {
                 $flags = 0;
                 foreach ($levels as $name) {
                     $flags |= LogLevel::named($name);
                 }
             } else {
                 $flags = $prop->readArray($section, 'appender.' . $appender . '.flags', LogLevel::ALL);
                 if (!is_int($flags)) {
                     $arrflags = $flags;
                     $flags = 0;
                     foreach ($arrflags as $f) {
                         try {
                             $flags |= LogLevel::named(substr($f, 12));
                             // 12 = strlen('LOGGER_FLAG_')
                         } catch (IllegalArgumentException $ignore) {
                             // ...
                         }
                     }
                 }
             }
             $a = $this->category[$section]->addAppender(XPClass::forName($appender)->newInstance(), $flags);
             $params = $prop->readArray($section, 'appender.' . $appender . '.params', array());
             // Params
             foreach ($params as $param) {
                 $a->{$param} = strftime($prop->readString($section, 'appender.' . $appender . '.param.' . $param, ''));
             }
             // Set context
             if ('' !== ($contextFQN = $prop->readString($section, 'context'))) {
                 $this->category[$section]->setContext(XPClass::forName($contextFQN)->newInstance());
             }
         }
     } while ($section = $prop->getNextSection());
 }
Пример #10
0
 private static function log_email($loglevel, $message, $entity_path = null, $judge_host = null)
 {
     if ($loglevel >= LOG_EMAIL_LEVEL) {
         $body = "Justitia produced a log entry.\n\n";
         $body .= "Type entry: " . LogLevel::toString($loglevel) . "\n";
         $body .= "Date: " . format_date(time()) . "\n";
         if ($entity_path != null) {
             $body .= "Entity path: " . $entity_path . "\n";
         }
         if ($judge_host != null) {
             $body .= "Judge host: " . $judge_host . "\n";
         }
         if (self::userid() != null) {
             $body .= "User: "******"\n";
         }
         if (self::ip() != null) {
             $body .= "IP address: " . self::ip() . "\n";
         }
         $body .= "Message: " . $message . "\n";
         mail(LOG_EMAIL_EMAIL_ADRESSES, "Justitia logging", $body);
     }
 }
Пример #11
0
 /**
  * Formats a logging event according to this layout
  *
  * @param   util.log.LoggingEvent event
  * @return  string
  */
 public function format(LoggingEvent $event)
 {
     return sprintf("[%s %5d %5s] %s%s\n", date('H:i:s', $event->getTimestamp()), $event->getProcessId(), strtolower(LogLevel::nameOf($event->getLevel())), NULL === ($context = $event->getContext()) ? '' : $context->format() . ' ', implode(' ', array_map(array($this, 'stringOf'), $event->getArguments())));
 }
Пример #12
0
 /**
  * @covers Phossa\Logger\LogLevel::getLevelCode
  * @expectedExceptionCode Phossa\Logger\Message\Message::INVALID_LOG_LEVEL
  * @expectedException Phossa\Logger\Exception\InvalidArgumentException
  */
 public function testGetLevelCode2()
 {
     $this->assertEquals(0, LogLevel::getLevelCode('', true));
 }
 /**
  * Formats a logging event according to this layout
  *
  * @param   util.log.LoggingEvent event
  * @return  string
  */
 public function format(LoggingEvent $event)
 {
     $out = '';
     foreach ($this->format as $token) {
         switch ($token) {
             case '%m':
                 $out .= implode(' ', array_map(array($this, 'stringOf'), $event->getArguments()));
                 break;
             case '%t':
                 $out .= gmdate('H:i:s', $event->getTimestamp());
                 break;
             case '%c':
                 $out .= $event->getCategory()->identifier;
                 break;
             case '%l':
                 $out .= strtolower(LogLevel::nameOf($event->getLevel()));
                 break;
             case '%L':
                 $out .= strtoupper(LogLevel::nameOf($event->getLevel()));
                 break;
             case '%p':
                 $out .= $event->getProcessId();
                 break;
             case '%x':
                 $out .= NULL == ($context = $event->getContext()) ? '' : $context->format();
                 break;
             default:
                 $out .= $token;
         }
     }
     return $out;
 }
Пример #14
0
 public function unknown()
 {
     LogLevel::named('@UNKNOWN@');
 }
Пример #15
0
 /**
  * Checks if the log level provided is a valid one according to the PSR-3
  * specification.
  * 
  * @param string $level the level to check for validity
  */
 protected function isLevelAllowed($level)
 {
     return in_array($level, LogLevel::all());
 }
Пример #16
0
 /**
  * Returns the configuration from $TYPO3_CONF_VARS['LOG'] as
  * hierarchical array for different components of the class hierarchy.
  *
  * @param string $configurationType Type of config to return (writer, processor)
  * @param string $loggerName Logger name
  * @throws \Psr\Log\InvalidArgumentException
  * @return array
  */
 protected function getConfigurationForLogger($configurationType, $loggerName)
 {
     // Split up the logger name (dot-separated) into its parts
     $explodedName = explode('.', $loggerName);
     // Search in the $TYPO3_CONF_VARS['LOG'] array
     // for these keys, for example "writerConfiguration"
     $configurationKey = $configurationType . 'Configuration';
     $configuration = $GLOBALS['TYPO3_CONF_VARS']['LOG'];
     $result = $configuration[$configurationKey] ?: array();
     // Walk from general to special (t3lib, t3lib.db, t3lib.db.foo)
     // and search for the most specific configuration
     foreach ($explodedName as $partOfClassName) {
         if (!empty($configuration[$partOfClassName][$configurationKey])) {
             $result = $configuration[$partOfClassName][$configurationKey];
         }
         $configuration = $configuration[$partOfClassName];
     }
     // Validate the config
     foreach ($result as $level => $unused) {
         try {
             LogLevel::validateLevel($level);
         } catch (\Psr\Log\InvalidArgumentException $e) {
             throw new \Psr\Log\InvalidArgumentException('The given severity level "' . htmlspecialchars($level) . '" for ' . $configurationKey . ' of logger "' . $loggerName . '" is not valid.', 1326406447);
         }
     }
     return $result;
 }
Пример #17
0
 /**
  * Adds a log record.
  *
  * @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
  * @param string $message Log message.
  * @param array $data Additional data to log
  * @return mixed
  */
 public function log($level, $message, array $data = array())
 {
     $level = LogLevel::normalizeLevel($level);
     LogLevel::validateLevel($level);
     if ($level > $this->minimumLogLevel) {
         return $this;
     }
     /** @var $record \TYPO3\CMS\Core\Log\LogRecord */
     $record = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(LogRecord::class, $this->name, $level, $message, $data);
     $record = $this->callProcessors($record);
     $this->writeLog($record);
     return $this;
 }