Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-12-01 04:36:54 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2014-12-01 04:36:54 +0300
commit20e84e7d9e6b0cc450cdb207fc5d1f1dbbd67e50 (patch)
tree7cc5c9f84107aa80a0b0dc84f0d8a75a0a1f06f2 /config
parent598d56e4d9d74c76fbfbfbe96a9f0af56a69bf15 (diff)
#6622 Logger refactoring: moved some configuration into the container
Diffstat (limited to 'config')
-rw-r--r--config/global.php75
1 files changed, 71 insertions, 4 deletions
diff --git a/config/global.php b/config/global.php
index 6a0f1da860..6cebcdce9d 100644
--- a/config/global.php
+++ b/config/global.php
@@ -1,6 +1,13 @@
<?php
use Interop\Container\ContainerInterface;
+use Piwik\Log\Formatter\AddRequestIdFormatter;
+use Piwik\Log\Formatter\ErrorHtmlFormatter;
+use Piwik\Log\Formatter\ErrorTextFormatter;
+use Piwik\Log\Formatter\ExceptionHtmlFormatter;
+use Piwik\Log\Formatter\ExceptionTextFormatter;
+use Piwik\Log\Formatter\HtmlPreFormatter;
+use Piwik\Log\Formatter\LineMessageFormatter;
return array(
@@ -20,17 +27,77 @@ return array(
return $root . '/tmp' . $instanceId;
}),
-
// Log
'Piwik\Log' => DI\factory(array('Piwik\Log\LoggerFactory', 'createLogger')),
+ 'log.processors' => array(
+ DI\link('Piwik\Log\Processor\SprintfProcessor'),
+ ),
+ 'Piwik\Log\Backend\FileBackend' => DI\object()
+ ->constructor(DI\link('log.formatter.text'), DI\link('log.file.filename')),
+ 'Piwik\Log\Backend\DatabaseBackend' => DI\object()
+ ->constructor(DI\link('log.formatter.text')),
+ 'Piwik\Log\Backend\StdOutBackend' => DI\object()
+ ->constructor(DI\link('log.formatter.html')),
+ 'log.file.filename' => DI\factory(function (ContainerInterface $c) {
+ $logPath = $c->get('old_config.log.logger_file_path');
+
+ // Absolute path
+ if (strpos($logPath, '/') === 0) {
+ return $logPath;
+ }
+
+ // Remove 'tmp/' at the beginning
+ if (strpos($logPath, 'tmp/') === 0) {
+ $logPath = substr($logPath, strlen('tmp'));
+ }
+
+ if (empty($logPath)) {
+ // Default log file
+ $logPath = '/logs/piwik.log';
+ }
+
+ $logPath = $c->get('path.tmp') . $logPath;
+ if (is_dir($logPath)) {
+ $logPath .= '/piwik.log';
+ }
+
+ return $logPath;
+ }),
+ 'log.formatter.text' => DI\factory(function (ContainerInterface $c) {
+ // Chain of responsibility pattern
+ $lineFormatter = new LineMessageFormatter($c->get('log.format'));
+
+ $exceptionFormatter = new ExceptionTextFormatter();
+ $exceptionFormatter->setNext($lineFormatter);
+
+ $errorFormatter = new ErrorTextFormatter();
+ $errorFormatter->setNext($exceptionFormatter);
+
+ return $errorFormatter;
+ }),
+ 'log.formatter.html' => DI\factory(function (ContainerInterface $c) {
+ // Chain of responsibility pattern
+ $lineFormatter = new LineMessageFormatter($c->get('log.format'));
+
+ $addRequestIdFormatter = new AddRequestIdFormatter();
+ $addRequestIdFormatter->setNext($lineFormatter);
+
+ $htmlPreFormatter = new HtmlPreFormatter();
+ $htmlPreFormatter->setNext($addRequestIdFormatter);
+
+ $exceptionFormatter = new ExceptionHtmlFormatter();
+ $exceptionFormatter->setNext($htmlPreFormatter);
+
+ $errorFormatter = new ErrorHtmlFormatter();
+ $errorFormatter->setNext($exceptionFormatter);
+
+ return $errorFormatter;
+ }),
'log.format' => DI\factory(function (ContainerInterface $c) {
if ($c->has('old_config.log.string_message_format')) {
return $c->get('old_config.log.string_message_format');
}
return '%level% %tag%[%datetime%] %message%';
}),
- 'log.processors' => array(
- DI\link('Piwik\Log\Processor\SprintfProcessor'),
- ),
);