From 528d5dcfe266e4b18f87b9fb51cfcb8e7782f8cc Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 1 Dec 2014 12:14:10 +1300 Subject: #6622 Logger refactoring: moved "log message processing" into "Processor" objects (to prepare the transition to Monolog) --- core/Log.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'core/Log.php') diff --git a/core/Log.php b/core/Log.php index a59d6857f6..54844f7dbb 100644 --- a/core/Log.php +++ b/core/Log.php @@ -139,11 +139,18 @@ class Log extends Singleton */ private $currentLogLevel = self::WARN; + /** + * Processors process log messages before they are being sent to backends. + * + * @var callable[] + */ + private $processors = array(); + /** * The array of callbacks executed when logging a message. Each callback writes a log * message to a logging backend. * - * @var array + * @var callable[] */ private $writers = array(); @@ -175,12 +182,14 @@ class Log extends Singleton * @param callable[] $writers * @param string $logMessageFormat * @param int $logLevel + * @param callable[] $processors */ - public function __construct(array $writers, $logMessageFormat, $logLevel) + public function __construct(array $writers, $logMessageFormat, $logLevel, array $processors) { $this->writers = $writers; $this->logMessageFormat = $logMessageFormat; $this->currentLogLevel = $logLevel; + $this->processors = $processors; } /** @@ -286,17 +295,9 @@ class Log extends Singleton } $datetime = date("Y-m-d H:i:s"); - if (is_string($message) - && !empty($sprintfParams) - ) { - // handle array sprintf parameters - foreach ($sprintfParams as &$param) { - if (is_array($param)) { - $param = json_encode($param); - } - } - $message = vsprintf($message, $sprintfParams); + foreach ($this->processors as $processor) { + $message = $processor($message, $sprintfParams, $level); } if (version_compare(phpversion(), '5.3.6', '>=')) { -- cgit v1.2.3