diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-03-26 04:38:38 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-03-26 04:38:38 +0300 |
commit | 20881540fcfafaff5993cd8fe4f5a40c6d63b77a (patch) | |
tree | 0b3d1f3b15a6ad8a5600a33b0e82f79e14c6ed57 | |
parent | aff497df5c07a41588d4ea1e7a3c1b5f8eec6d8f (diff) | |
parent | c4d736682d00200305295afab5cc07ac7dc3e8bb (diff) |
Merge pull request #7542 from piwik/7535
Log warning but do not throw if trying to log a non-string message
-rw-r--r-- | core/Log.php | 6 | ||||
-rw-r--r-- | plugins/Monolog/Processor/SprintfProcessor.php | 4 | ||||
-rw-r--r-- | plugins/Monolog/config/config.php | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/core/Log.php b/core/Log.php index 260e57fea6..82f2beab66 100644 --- a/core/Log.php +++ b/core/Log.php @@ -209,8 +209,12 @@ class Log extends Singleton $parameters['exception'] = $message; $message = $message->getMessage(); } + if (! is_string($message)) { - throw new \InvalidArgumentException('Trying to log a message that is not a string'); + $this->logger->warning('Trying to log a message that is not a string', array( + 'exception' => new \InvalidArgumentException + )); + return; } $this->logger->log($level, $message, $parameters); diff --git a/plugins/Monolog/Processor/SprintfProcessor.php b/plugins/Monolog/Processor/SprintfProcessor.php index dafa46e5ba..f06b6154de 100644 --- a/plugins/Monolog/Processor/SprintfProcessor.php +++ b/plugins/Monolog/Processor/SprintfProcessor.php @@ -18,7 +18,7 @@ class SprintfProcessor $message = $record['message']; $parameters = $record['context']; - if (is_string($message) && !empty($parameters)) { + if (is_string($message) && !empty($parameters) && strpos($message, '%') !== false) { $parameters = $this->ensureParametersAreStrings($parameters); $record['message'] = vsprintf($message, $parameters); @@ -32,6 +32,8 @@ class SprintfProcessor foreach ($parameters as &$param) { if (is_array($param)) { $param = json_encode($param); + } elseif (is_object($param)) { + $param = get_class($param); } } diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php index b95a143c97..7005573ced 100644 --- a/plugins/Monolog/config/config.php +++ b/plugins/Monolog/config/config.php @@ -31,10 +31,10 @@ return array( }), 'log.processors' => array( + DI\link('Piwik\Plugins\Monolog\Processor\SprintfProcessor'), DI\link('Piwik\Plugins\Monolog\Processor\ClassNameProcessor'), DI\link('Piwik\Plugins\Monolog\Processor\RequestIdProcessor'), DI\link('Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor'), - DI\link('Piwik\Plugins\Monolog\Processor\SprintfProcessor'), DI\link('Monolog\Processor\PsrLogMessageProcessor'), DI\link('Piwik\Plugins\Monolog\Processor\TokenProcessor'), ), |