'local_tags' => false,
// logger_adapter (String)
- // Sets the logging adapter of Friendica globally (monolog, syslog)
+ // Sets the logging adapter of Friendica globally (monolog, syslog, stream)
'logger_adapter' => 'monolog',
// max_batch_queue (Integer)
use Friendica\Util\Introspection;
use Friendica\Util\Logger\Monolog\FriendicaDevelopHandler;
use Friendica\Util\Logger\Monolog\FriendicaIntrospectionProcessor;
+use Friendica\Util\Logger\StreamLogger;
use Friendica\Util\Logger\SyslogLogger;
use Friendica\Util\Logger\VoidLogger;
use Friendica\Util\Logger\WorkerLogger;
}
$introspection = new Introspection(self::$ignoreClassList);
+ $level = $config->get('system', 'loglevel');
switch ($config->get('system', 'logger_adapter', 'monolog')) {
- case 'syslog':
- $level = $config->get('system', 'loglevel');
+ case 'syslog':
$logger = new SyslogLogger($channel, $introspection, $profiler, $level);
break;
+
+ case 'stream':
+ $logger = new StreamLogger($channel, $introspection, $profiler, $level);
+ break;
+
case 'monolog':
default:
$loggerTimeZone = new \DateTimeZone('UTC');
$logger->pushProcessor(new FriendicaIntrospectionProcessor($introspection, LogLevel::DEBUG));
$stream = $config->get('system', 'logfile');
- $level = $config->get('system', 'loglevel');
$loglevel = self::mapLegacyConfigDebugLevel((string)$level);
static::addStreamHandler($logger, $stream, $loglevel);
public function emergency($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::EMERGENCY, $message, $context);
+ $this->addEntry(LogLevel::EMERGENCY, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function alert($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::ALERT, $message, $context);
+ $this->addEntry(LogLevel::ALERT, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function critical($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::CRITICAL, $message, $context);
+ $this->addEntry(LogLevel::CRITICAL, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function error($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::ERROR, $message, $context);
+ $this->addEntry(LogLevel::ERROR, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function warning($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::WARNING, $message, $context);
+ $this->addEntry(LogLevel::WARNING, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function notice($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::NOTICE, $message, $context);
+ $this->addEntry(LogLevel::NOTICE, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function info($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::INFO, $message, $context);
+ $this->addEntry(LogLevel::INFO, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function debug($message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry(LogLevel::DEBUG, $message, $context);
+ $this->addEntry(LogLevel::DEBUG, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
public function log($level, $message, array $context = array())
{
$stamp1 = microtime(true);
- $this->addEntry($level, $message, $context);
+ $this->addEntry($level, (string) $message, $context);
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
}
}
use Friendica\Util\Profiler;
/**
- * A Logger instance for logging into a stream
+ * A Logger instance for logging into a stream (file, stdout, stderr)
*/
class StreamLogger extends AbstractFriendicaLogger
{
- public function __construct($channel, Introspection $introspection, Profiler $profiler)
+ /**
+ * The minimum loglevel at which this logger will be triggered
+ * @var string
+ */
+ private $logLevel;
+
+ public function __construct($channel, Introspection $introspection, Profiler $profiler, $level)
{
parent::__construct($channel, $introspection, $profiler);
+ $this->logLevel = $level;
}
/**
$this->introspection->addClasses(array(self::class));
}
+ /**
+ * Adds a new entry to the syslog
+ *
+ * @param int $level
+ * @param string $message
+ * @param array $context
+ *
+ * @throws InternalServerErrorException if the syslog isn't available
+ */
+ protected function addEntry($level, $message, $context = [])
+ {
+ $logLevel = $this->mapLevelToPriority($level);
+
+ if ($logLevel >= $this->logLevel) {
+ return;
+ }
+
+ $formattedLog = $this->formatLog($logLevel, $message, $context);
+ $this->write($logLevel, $formattedLog);
+ }
+
/**
* Maps the LogLevel (@see LogLevel ) to a SysLog priority (@see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters )
*
return $this->logLevels[$level];
}
+ /**
+ * Closes the Syslog
+ */
+ public function close()
+ {
+ closelog();
+ }
+
/**
* Writes a message to the syslog
* @see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters
syslog($priority, $message);
}
- /**
- * Closes the Syslog
- */
- public function close()
- {
- closelog();
- }
-
/**
* Formats a log record for the syslog output
*
return $logMessage;
}
-
- /**
- * Adds a new entry to the syslog
- *
- * @param int $level
- * @param string $message
- * @param array $context
- *
- * @throws InternalServerErrorException if the syslog isn't available
- */
- protected function addEntry($level, $message, $context = [])
- {
- $logLevel = $this->mapLevelToPriority($level);
-
- if ($logLevel >= $this->logLevel) {
- return;
- }
-
- $formattedLog = $this->formatLog($level, $message, $context);
- $this->write($level, $formattedLog);
- }
}