diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-04 08:29:33 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-04 08:29:33 +0300 |
commit | a59667bf04c670e26c1116985481e688084efc4f (patch) | |
tree | a5d1ca9a9ce30720e6b1ad07d06e09796123b204 /core | |
parent | 14cf2581242c75907fb554e08a30041ad107f558 (diff) |
#6622 Logger refactoring: removed the "Log.getAvailableWriters" event
Adding new log backends will later be possible by configuring Monolog handlers
Diffstat (limited to 'core')
-rw-r--r-- | core/Log.php | 2 | ||||
-rw-r--r-- | core/Log/LoggerFactory.php | 58 |
2 files changed, 8 insertions, 52 deletions
diff --git a/core/Log.php b/core/Log.php index 8bcf91df9c..d22b88160b 100644 --- a/core/Log.php +++ b/core/Log.php @@ -114,8 +114,6 @@ class Log extends Singleton const LOGGER_FILE_PATH_CONFIG_OPTION = 'logger_file_path'; const STRING_MESSAGE_FORMAT_OPTION = 'string_message_format'; - const GET_AVAILABLE_WRITERS_EVENT = 'Log.getAvailableWriters'; - /** * The backtrace string to use when testing. * diff --git a/core/Log/LoggerFactory.php b/core/Log/LoggerFactory.php index f9f437d468..fe783cb42c 100644 --- a/core/Log/LoggerFactory.php +++ b/core/Log/LoggerFactory.php @@ -12,7 +12,6 @@ use Interop\Container\ContainerInterface; use Piwik\Config; use Piwik\Log; use Piwik\Log\Backend\StdErrBackend; -use Piwik\Piwik; class LoggerFactory { @@ -39,22 +38,20 @@ class LoggerFactory return array(); } - $availableWriters = self::getAvailableWriters(); + $classes = array( + 'file' => 'Piwik\Log\Backend\FileBackend', + 'screen' => 'Piwik\Log\Backend\StdOutBackend', + 'database' => 'Piwik\Log\Backend\DatabaseBackend', + ); $writerNames = array_map('trim', $writerNames); $writers = array(); foreach ($writerNames as $writerName) { - if (! isset($availableWriters[$writerName])) { - continue; + if (isset($classes[$writerName])) { + $class = $classes[$writerName]; + $writers[$writerName] = $container->get($class); } - - $writer = $availableWriters[$writerName]; - if (is_string($writer)) { - $writer = $container->get($writer); - } - - $writers[$writerName] = $writer; } // Always add the stderr backend @@ -63,43 +60,4 @@ class LoggerFactory return $writers; } - - private static function getAvailableWriters() - { - $writers = array(); - - /** - * This event is called when the Log instance is created. Plugins can use this event to - * make new logging writers available. - * - * A logging writer is a callback with the following signature: - * - * function (int $level, string $tag, string $datetime, string $message) - * - * `$level` is the log level to use, `$tag` is the log tag used, `$datetime` is the date time - * of the logging call and `$message` is the formatted log message. - * - * Logging writers must be associated by name in the array passed to event handlers. The - * name specified can be used in Piwik's INI configuration. - * - * **Example** - * - * public function getAvailableWriters(&$writers) { - * $writers['myloggername'] = function ($level, $tag, $datetime, $message) { - * // ... - * }; - * } - * - * // 'myloggername' can now be used in the log_writers config option. - * - * @param array $writers Array mapping writer names with logging writers. - */ - Piwik::postEvent(Log::GET_AVAILABLE_WRITERS_EVENT, array(&$writers)); - - $writers['file'] = 'Piwik\Log\Backend\FileBackend'; - $writers['screen'] = 'Piwik\Log\Backend\StdOutBackend'; - $writers['database'] = 'Piwik\Log\Backend\DatabaseBackend'; - - return $writers; - } } |