From 764db8ebc3fa705c43ce4af3eec73ca3237eeb0e Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 27 Feb 2019 16:40:35 +0100 Subject: [PATCH 1/5] Adding SyslogLogger --- config/defaults.config.php | 4 + src/Factory/LoggerFactory.php | 42 ++-- ...pectionProcessor.php => Introspection.php} | 33 ++- src/Util/Logger/SyslogLogger.php | 215 ++++++++++++++++++ 4 files changed, 267 insertions(+), 27 deletions(-) rename src/Util/Logger/{FriendicaIntrospectionProcessor.php => Introspection.php} (83%) create mode 100644 src/Util/Logger/SyslogLogger.php diff --git a/config/defaults.config.php b/config/defaults.config.php index 694f75c220..000b0f443b 100644 --- a/config/defaults.config.php +++ b/config/defaults.config.php @@ -209,6 +209,10 @@ return [ // If activated, all hashtags will point to the local server. 'local_tags' => false, + // logger_adapter (String) + // Sets the logging adapter of Friendica globally (monolog, syslog) + 'logger_adapter' => 'syslog', + // max_batch_queue (Integer) // Maximum number of batched queue items for a single contact before subsequent messages are discarded. 'max_batch_queue' => 1000, diff --git a/src/Factory/LoggerFactory.php b/src/Factory/LoggerFactory.php index 77a09637c4..c6788aa62c 100644 --- a/src/Factory/LoggerFactory.php +++ b/src/Factory/LoggerFactory.php @@ -6,7 +6,8 @@ use Friendica\Core\Config\Configuration; use Friendica\Core\Logger; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Logger\FriendicaDevelopHandler; -use Friendica\Util\Logger\FriendicaIntrospectionProcessor; +use Friendica\Util\Logger\Introspection; +use Friendica\Util\Logger\SyslogLogger; use Friendica\Util\Profiler; use Monolog; use Psr\Log\LoggerInterface; @@ -29,21 +30,32 @@ class LoggerFactory */ public static function create($channel, Configuration $config) { - $logger = new Monolog\Logger($channel); - $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); - $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); - $logger->pushProcessor(new Monolog\Processor\UidProcessor()); - $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, [Logger::class, Profiler::class])); + switch ($config->get('system', 'logger_adapter', 'monolog')) { + case 'syslog': + $intorspector = new Introspection(LOG_DEBUG, [Logger::class, SyslogLogger::class, Profiler::class]); + $level = $config->get('system', 'loglevel'); - $debugging = $config->get('system', 'debugging'); - $stream = $config->get('system', 'logfile'); - $level = $config->get('system', 'loglevel'); + $logger = new SyslogLogger($channel, $intorspector, $level); + break; + case 'monolog': + default: + $logger = new Monolog\Logger($channel); + $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); + $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); + $logger->pushProcessor(new Monolog\Processor\UidProcessor()); + $logger->pushProcessor(new Introspection(LogLevel::DEBUG, [Logger::class, Profiler::class])); - if ($debugging) { - $loglevel = self::mapLegacyConfigDebugLevel((string)$level); - static::addStreamHandler($logger, $stream, $loglevel); - } else { - static::addVoidHandler($logger); + $debugging = $config->get('system', 'debugging'); + $stream = $config->get('system', 'logfile'); + $level = $config->get('system', 'loglevel'); + + if ($debugging) { + $loglevel = self::mapLegacyConfigDebugLevel((string)$level); + static::addStreamHandler($logger, $stream, $loglevel); + } else { + static::addVoidHandler($logger); + } + break; } Logger::init($logger); @@ -78,7 +90,7 @@ class LoggerFactory $logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor()); $logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor()); $logger->pushProcessor(new Monolog\Processor\UidProcessor()); - $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger'])); + $logger->pushProcessor(new Introspection(LogLevel::DEBUG, ['Friendica\\Core\\Logger'])); $logger->pushHandler(new FriendicaDevelopHandler($developerIp)); diff --git a/src/Util/Logger/FriendicaIntrospectionProcessor.php b/src/Util/Logger/Introspection.php similarity index 83% rename from src/Util/Logger/FriendicaIntrospectionProcessor.php rename to src/Util/Logger/Introspection.php index aa3933a215..83fec6c50c 100644 --- a/src/Util/Logger/FriendicaIntrospectionProcessor.php +++ b/src/Util/Logger/Introspection.php @@ -11,7 +11,7 @@ use Monolog\Processor\ProcessorInterface; * Based on the class IntrospectionProcessor without the "class" information * @see IntrospectionProcessor */ -class FriendicaIntrospectionProcessor implements ProcessorInterface +class Introspection implements ProcessorInterface { private $level; @@ -42,7 +42,22 @@ class FriendicaIntrospectionProcessor implements ProcessorInterface if ($record['level'] < $this->level) { return $record; } + // we should have the call source now + $record['extra'] = array_merge( + $record['extra'], + $this->getRecord() + ); + return $record; + } + + /** + * Returns the introspection record of the current call + * + * @return array + */ + public function getRecord() + { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $i = 1; @@ -53,17 +68,11 @@ class FriendicaIntrospectionProcessor implements ProcessorInterface $i += $this->skipStackFramesCount; - // we should have the call source now - $record['extra'] = array_merge( - $record['extra'], - [ - 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null, - 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, - 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, - ] - ); - - return $record; + return [ + 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null, + 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, + 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, + ]; } /** diff --git a/src/Util/Logger/SyslogLogger.php b/src/Util/Logger/SyslogLogger.php new file mode 100644 index 0000000000..3734e688e9 --- /dev/null +++ b/src/Util/Logger/SyslogLogger.php @@ -0,0 +1,215 @@ + LOG_DEBUG, + LogLevel::INFO => LOG_INFO, + LogLevel::NOTICE => LOG_NOTICE, + LogLevel::WARNING => LOG_WARNING, + LogLevel::ERROR => LOG_ERR, + LogLevel::CRITICAL => LOG_CRIT, + LogLevel::ALERT => LOG_ALERT, + LogLevel::EMERGENCY => LOG_EMERG, + ]; + + /** + * The standard ident of the syslog (added to each message) + * @var string + */ + private $ident; + + /** + * Indicates what logging options will be used when generating a log message + * @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters + * + * @var int + */ + private $logOpts; + + /** + * Used to specify what type of program is logging the message + * @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters + * + * @var int + */ + private $logFacility; + + /** + * The minimum loglevel at which this logger will be triggered + * @var int + */ + private $logLevel; + + /** + * The Introspector for the current call + * @var Introspection + */ + private $introspection; + + /** + * @param string $channel The channel (Syslog ident) + * @param string $level The minimum loglevel at which this logger will be triggered + * @param int $logOpts Indicates what logging options will be used when generating a log message + * @param int $logFacility Used to specify what type of program is logging the message + * + * @throws InternalServerErrorException if the loglevel isn't valid + */ + public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER) + { + $this->ident = $channel; + $this->logOpts = $logOpts; + $this->logFacility = $logFacility; + $this->logLevel = $this->mapLevelToPriority($level); + $this->introspection = $introspection; + } + + /** + * Maps the LogLevel (@see LogLevel ) to a SysLog priority (@see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters ) + * + * @param string $level A LogLevel + * + * @return int The SysLog priority + * + * @throws \Psr\Log\InvalidArgumentException If the loglevel isn't valid + */ + public function mapLevelToPriority($level) + { + if (!array_key_exists($level, $this->logLevels)) { + throw new InvalidArgumentException('LogLevel \'' . $level . '\' isn\'t valid.'); + } + + return $this->logLevels[$level]; + } + + /** + * Writes a message to the syslog + * + * @param int $priority The Priority ( @see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters ) + * @param string $message The message of the log + * @throws InternalServerErrorException if syslog cannot be used + */ + private function write($priority, $message) + { + if (!openlog($this->ident, $this->logOpts, $this->logFacility)) { + throw new InternalServerErrorException('Can\'t open syslog for ident "' . $this->ident . '" and facility "' . $this->logFacility . '""'); + } + + syslog($priority, $message); + } + + public function close() + { + closelog(); + } + + private function formatLog($level, $message, $context = []) + { + $logMessage = ''; + + $logMessage .= $this->ident . ' '; + $logMessage .= '[' . $level . ']: '; + $logMessage .= $message . ' '; + $logMessage .= json_encode($context) . ' - '; + $logMessage .= json_encode($this->introspection->getRecord()); + + return $logMessage; + } + + private function addEntry($level, $message, $context = []) + { + if ($level >= $this->logLevel) { + return; + } + + $formattedLog = $this->formatLog($level, $message, $context); + $this->write($level, $formattedLog); + } + + /** + * {@inheritdoc} + */ + public function emergency($message, array $context = array()) + { + $this->addEntry(LOG_EMERG, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function alert($message, array $context = array()) + { + $this->addEntry(LOG_ALERT, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function critical($message, array $context = array()) + { + $this->addEntry(LOG_CRIT, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function error($message, array $context = array()) + { + $this->addEntry(LOG_ERR, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function warning($message, array $context = array()) + { + $this->addEntry(LOG_WARNING, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function notice($message, array $context = array()) + { + $this->addEntry(LOG_NOTICE, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function info($message, array $context = array()) + { + $this->addEntry(LOG_INFO, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function debug($message, array $context = array()) + { + $this->addEntry(LOG_DEBUG, $message, $context); + } + + /** + * {@inheritdoc} + */ + public function log($level, $message, array $context = array()) + { + $logLevel = $this->mapLevelToPriority($level); + $this->addEntry($logLevel, $message, $context); + } +} From 4ddd9e4dde96cad8bc22672113322694c866fa53 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 27 Feb 2019 16:46:53 +0100 Subject: [PATCH 2/5] Adding ident --- src/Util/Logger/SyslogLogger.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Util/Logger/SyslogLogger.php b/src/Util/Logger/SyslogLogger.php index 3734e688e9..dc57f15163 100644 --- a/src/Util/Logger/SyslogLogger.php +++ b/src/Util/Logger/SyslogLogger.php @@ -13,6 +13,8 @@ use Psr\Log\LogLevel; */ class SyslogLogger implements LoggerInterface { + const IDENT = 'Friendica'; + /** * Translates LogLevel log levels to syslog log priorities. */ @@ -31,7 +33,7 @@ class SyslogLogger implements LoggerInterface * The standard ident of the syslog (added to each message) * @var string */ - private $ident; + private $channel; /** * Indicates what logging options will be used when generating a log message @@ -62,7 +64,7 @@ class SyslogLogger implements LoggerInterface private $introspection; /** - * @param string $channel The channel (Syslog ident) + * @param string $channel The output channel * @param string $level The minimum loglevel at which this logger will be triggered * @param int $logOpts Indicates what logging options will be used when generating a log message * @param int $logFacility Used to specify what type of program is logging the message @@ -71,7 +73,7 @@ class SyslogLogger implements LoggerInterface */ public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER) { - $this->ident = $channel; + $this->channel = $channel; $this->logOpts = $logOpts; $this->logFacility = $logFacility; $this->logLevel = $this->mapLevelToPriority($level); @@ -105,23 +107,35 @@ class SyslogLogger implements LoggerInterface */ private function write($priority, $message) { - if (!openlog($this->ident, $this->logOpts, $this->logFacility)) { - throw new InternalServerErrorException('Can\'t open syslog for ident "' . $this->ident . '" and facility "' . $this->logFacility . '""'); + if (!openlog(self::IDENT, $this->logOpts, $this->logFacility)) { + throw new InternalServerErrorException('Can\'t open syslog for ident "' . $this->channel . '" and facility "' . $this->logFacility . '""'); } syslog($priority, $message); } + /** + * Closes the Syslog + */ public function close() { closelog(); } + /** + * Formats a log record for the syslog output + * + * @param int $level The loglevel/priority + * @param string $message The message + * @param array $context The context of this call + * + * @return string the formatted syslog output + */ private function formatLog($level, $message, $context = []) { $logMessage = ''; - $logMessage .= $this->ident . ' '; + $logMessage .= $this->channel . ' '; $logMessage .= '[' . $level . ']: '; $logMessage .= $message . ' '; $logMessage .= json_encode($context) . ' - '; From d3067466f515daff7bc79389044d3ab42bcaaabe Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 27 Feb 2019 17:03:01 +0100 Subject: [PATCH 3/5] Code cleanup --- src/Util/Logger/SyslogLogger.php | 80 ++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/src/Util/Logger/SyslogLogger.php b/src/Util/Logger/SyslogLogger.php index dc57f15163..994c0a1e24 100644 --- a/src/Util/Logger/SyslogLogger.php +++ b/src/Util/Logger/SyslogLogger.php @@ -19,18 +19,18 @@ class SyslogLogger implements LoggerInterface * Translates LogLevel log levels to syslog log priorities. */ private $logLevels = [ - LogLevel::DEBUG => LOG_DEBUG, - LogLevel::INFO => LOG_INFO, - LogLevel::NOTICE => LOG_NOTICE, - LogLevel::WARNING => LOG_WARNING, - LogLevel::ERROR => LOG_ERR, - LogLevel::CRITICAL => LOG_CRIT, - LogLevel::ALERT => LOG_ALERT, + LogLevel::DEBUG => LOG_DEBUG, + LogLevel::INFO => LOG_INFO, + LogLevel::NOTICE => LOG_NOTICE, + LogLevel::WARNING => LOG_WARNING, + LogLevel::ERROR => LOG_ERR, + LogLevel::CRITICAL => LOG_CRIT, + LogLevel::ALERT => LOG_ALERT, LogLevel::EMERGENCY => LOG_EMERG, ]; /** - * The standard ident of the syslog (added to each message) + * The channel of the current process (added to each message) * @var string */ private $channel; @@ -65,11 +65,9 @@ class SyslogLogger implements LoggerInterface /** * @param string $channel The output channel - * @param string $level The minimum loglevel at which this logger will be triggered + * @param string $level The minimum loglevel at which this logger will be triggered * @param int $logOpts Indicates what logging options will be used when generating a log message * @param int $logFacility Used to specify what type of program is logging the message - * - * @throws InternalServerErrorException if the loglevel isn't valid */ public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER) { @@ -100,9 +98,11 @@ class SyslogLogger implements LoggerInterface /** * Writes a message to the syslog + * @see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters + * + * @param int $priority The Priority + * @param string $message The message of the log * - * @param int $priority The Priority ( @see http://php.net/manual/en/function.syslog.php#refsect1-function.syslog-parameters ) - * @param string $message The message of the log * @throws InternalServerErrorException if syslog cannot be used */ private function write($priority, $message) @@ -125,25 +125,58 @@ class SyslogLogger implements LoggerInterface /** * Formats a log record for the syslog output * - * @param int $level The loglevel/priority + * @param int $level The loglevel/priority * @param string $message The message - * @param array $context The context of this call + * @param array $context The context of this call * * @return string the formatted syslog output */ private function formatLog($level, $message, $context = []) { - $logMessage = ''; + $logMessage = ''; $logMessage .= $this->channel . ' '; $logMessage .= '[' . $level . ']: '; - $logMessage .= $message . ' '; - $logMessage .= json_encode($context) . ' - '; - $logMessage .= json_encode($this->introspection->getRecord()); + $logMessage .= $this->psrInterpolate($message, $context) . ' '; + $logMessage .= @json_encode($context) . ' - '; + $logMessage .= @json_encode($this->introspection->getRecord()); return $logMessage; } + /** + * Simple interpolation of PSR-3 compliant replacements ( between '{' and '}' ) + * @see https://www.php-fig.org/psr/psr-3/#12-message + * + * @param string $message + * @param array $context + * + * @return string the interpolated message + */ + private function psrInterpolate($message, array $context = array()) + { + $replace = []; + foreach ($context as $key => $value) { + // check that the value can be casted to string + if (!is_array($value) && (!is_object($value) || method_exists($value, '__toString'))) { + $replace['{' . $key . '}'] = $value; + } elseif (is_array($value)) { + $replace['{' . $key . '}'] = @json_encode($value); + } + } + + return strtr($message, $replace); + } + + /** + * Adds a new entry to the syslog + * + * @param int $level + * @param string $message + * @param array $context + * + * @throws InternalServerErrorException if the syslog isn't available + */ private function addEntry($level, $message, $context = []) { if ($level >= $this->logLevel) { @@ -156,6 +189,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function emergency($message, array $context = array()) { @@ -164,6 +198,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function alert($message, array $context = array()) { @@ -172,6 +207,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function critical($message, array $context = array()) { @@ -180,6 +216,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function error($message, array $context = array()) { @@ -188,6 +225,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function warning($message, array $context = array()) { @@ -196,6 +234,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function notice($message, array $context = array()) { @@ -204,6 +243,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function info($message, array $context = array()) { @@ -212,6 +252,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function debug($message, array $context = array()) { @@ -220,6 +261,7 @@ class SyslogLogger implements LoggerInterface /** * {@inheritdoc} + * @throws InternalServerErrorException if the syslog isn't available */ public function log($level, $message, array $context = array()) { From dfe1bb32462cfc3f98f50f040a17a5864ece89ed Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 27 Feb 2019 17:29:32 +0100 Subject: [PATCH 4/5] Adding UID and Level To String mapping --- src/Util/Logger/Introspection.php | 4 +-- src/Util/Logger/SyslogLogger.php | 46 ++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/Util/Logger/Introspection.php b/src/Util/Logger/Introspection.php index 83fec6c50c..f99225f9a2 100644 --- a/src/Util/Logger/Introspection.php +++ b/src/Util/Logger/Introspection.php @@ -69,8 +69,8 @@ class Introspection implements ProcessorInterface $i += $this->skipStackFramesCount; return [ - 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null, - 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, + 'file' => isset($trace[$i - 1]['file']) ? basename($trace[$i - 1]['file']) : null, + 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, ]; } diff --git a/src/Util/Logger/SyslogLogger.php b/src/Util/Logger/SyslogLogger.php index 994c0a1e24..19395157d2 100644 --- a/src/Util/Logger/SyslogLogger.php +++ b/src/Util/Logger/SyslogLogger.php @@ -3,6 +3,7 @@ namespace Friendica\Util\Logger; use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Util\Strings; use Psr\Log\InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; @@ -17,18 +18,34 @@ class SyslogLogger implements LoggerInterface /** * Translates LogLevel log levels to syslog log priorities. + * @var array */ private $logLevels = [ - LogLevel::DEBUG => LOG_DEBUG, - LogLevel::INFO => LOG_INFO, - LogLevel::NOTICE => LOG_NOTICE, - LogLevel::WARNING => LOG_WARNING, - LogLevel::ERROR => LOG_ERR, - LogLevel::CRITICAL => LOG_CRIT, - LogLevel::ALERT => LOG_ALERT, + LogLevel::DEBUG => LOG_DEBUG, + LogLevel::INFO => LOG_INFO, + LogLevel::NOTICE => LOG_NOTICE, + LogLevel::WARNING => LOG_WARNING, + LogLevel::ERROR => LOG_ERR, + LogLevel::CRITICAL => LOG_CRIT, + LogLevel::ALERT => LOG_ALERT, LogLevel::EMERGENCY => LOG_EMERG, ]; + /** + * Translates log priorities to string outputs + * @var array + */ + private $logToString = [ + LOG_DEBUG => 'DEBUG', + LOG_INFO => 'INFO', + LOG_NOTICE => 'NOTICE', + LOG_WARNING => 'WARNING', + LOG_ERR => 'ERROR', + LOG_CRIT => 'CRITICAL', + LOG_ALERT => 'ALERT', + LOG_EMERG => 'EMERGENCY' + ]; + /** * The channel of the current process (added to each message) * @var string @@ -63,6 +80,12 @@ class SyslogLogger implements LoggerInterface */ private $introspection; + /** + * The UID of the current call + * @var string + */ + private $logUid; + /** * @param string $channel The output channel * @param string $level The minimum loglevel at which this logger will be triggered @@ -71,6 +94,7 @@ class SyslogLogger implements LoggerInterface */ public function __construct($channel, Introspection $introspection, $level = LogLevel::NOTICE, $logOpts = LOG_PID, $logFacility = LOG_USER) { + $this->logUid = Strings::getRandomHex(6); $this->channel = $channel; $this->logOpts = $logOpts; $this->logFacility = $logFacility; @@ -133,19 +157,21 @@ class SyslogLogger implements LoggerInterface */ private function formatLog($level, $message, $context = []) { + $record = $this->introspection->getRecord(); + $record = array_merge($record, ['uid' => $this->logUid]); $logMessage = ''; $logMessage .= $this->channel . ' '; - $logMessage .= '[' . $level . ']: '; + $logMessage .= '[' . $this->logToString[$level] . ']: '; $logMessage .= $this->psrInterpolate($message, $context) . ' '; $logMessage .= @json_encode($context) . ' - '; - $logMessage .= @json_encode($this->introspection->getRecord()); + $logMessage .= @json_encode($record); return $logMessage; } /** - * Simple interpolation of PSR-3 compliant replacements ( between '{' and '}' ) + * Simple interpolation of PSR-3 compliant replacements ( variables between '{' and '}' ) * @see https://www.php-fig.org/psr/psr-3/#12-message * * @param string $message From 6738ec09d217055ea94d42cfe044dd0f2c0e2c82 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 27 Feb 2019 17:30:50 +0100 Subject: [PATCH 5/5] revert wrong default value --- config/defaults.config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/defaults.config.php b/config/defaults.config.php index 000b0f443b..d40d0c68d8 100644 --- a/config/defaults.config.php +++ b/config/defaults.config.php @@ -211,7 +211,7 @@ return [ // logger_adapter (String) // Sets the logging adapter of Friendica globally (monolog, syslog) - 'logger_adapter' => 'syslog', + 'logger_adapter' => 'monolog', // max_batch_queue (Integer) // Maximum number of batched queue items for a single contact before subsequent messages are discarded.