1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?php
use Interop\Container\ContainerInterface;
use Monolog\Logger;
use Piwik\Log;
use Piwik\Cache\Eager;
use Piwik\SettingsServer;
return array(
'path.root' => PIWIK_USER_PATH,
'path.tmp' => function (ContainerInterface $c) {
$root = $c->get('path.root');
// TODO remove that special case and instead have plugins override 'path.tmp' to add the instance id
if ($c->has('ini.General.instance_id')) {
$instanceId = $c->get('ini.General.instance_id');
$instanceId = $instanceId ? '/' . $instanceId : '';
} else {
$instanceId = '';
}
return $root . '/tmp' . $instanceId;
},
'path.cache' => DI\string('{path.tmp}/cache/tracker/'),
'Piwik\Cache\Eager' => function (ContainerInterface $c) {
$backend = $c->get('Piwik\Cache\Backend');
$cacheId = $c->get('cache.eager.cache_id');
if (SettingsServer::isTrackerApiRequest()) {
$eventToPersist = 'Tracker.end';
$cacheId .= 'tracker';
} else {
$eventToPersist = 'Request.dispatch.end';
$cacheId .= 'ui';
}
$cache = new Eager($backend, $cacheId);
\Piwik\Piwik::addAction($eventToPersist, function () use ($cache) {
$cache->persistCacheIfNeeded(43200);
});
return $cache;
},
'Piwik\Cache\Backend' => function (ContainerInterface $c) {
return \Piwik\Cache::buildBackend($c->get('ini.Cache.backend'));
},
'cache.eager.cache_id' => function () {
return 'eagercache-' . str_replace(array('.', '-'), '', \Piwik\Version::VERSION) . '-';
},
// Log
'Psr\Log\LoggerInterface' => DI\object('Monolog\Logger')
->constructor('piwik', DI\link('log.handlers'), DI\link('log.processors')),
'log.handlers' => DI\factory(function (ContainerInterface $c) {
if ($c->has('ini.log.log_writers')) {
$writerNames = $c->get('ini.log.log_writers');
} else {
return array();
}
$classes = array(
'file' => 'Piwik\Log\Handler\FileHandler',
'screen' => 'Piwik\Log\Handler\WebNotificationHandler',
'database' => 'Piwik\Log\Handler\DatabaseHandler',
);
$writerNames = array_map('trim', $writerNames);
$writers = array();
foreach ($writerNames as $writerName) {
if (isset($classes[$writerName])) {
$writers[$writerName] = $c->get($classes[$writerName]);
}
}
return array_values($writers);
}),
'log.processors' => array(
DI\link('Piwik\Log\Processor\ClassNameProcessor'),
DI\link('Piwik\Log\Processor\RequestIdProcessor'),
DI\link('Piwik\Log\Processor\ExceptionToTextProcessor'),
DI\link('Piwik\Log\Processor\SprintfProcessor'),
DI\link('Monolog\Processor\PsrLogMessageProcessor'),
),
'Piwik\Log\Handler\FileHandler' => DI\object()
->constructor(DI\link('log.file.filename'), DI\link('log.level'))
->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')),
'Piwik\Log\Handler\DatabaseHandler' => DI\object()
->constructor(DI\link('log.level'))
->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')),
'Piwik\Log\Handler\WebNotificationHandler' => DI\object()
->constructor(DI\link('log.level'))
->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')),
'log.level' => DI\factory(function (ContainerInterface $c) {
if ($c->has('ini.log.log_level')) {
$level = strtoupper($c->get('ini.log.log_level'));
if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) {
return Log::getMonologLevel(constant('Piwik\Log::'.strtoupper($level)));
}
}
return Logger::WARNING;
}),
'log.file.filename' => DI\factory(function (ContainerInterface $c) {
$logPath = $c->get('ini.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;
}),
'Piwik\Log\Formatter\LineMessageFormatter' => DI\object()
->constructor(DI\link('log.format')),
'log.format' => DI\factory(function (ContainerInterface $c) {
if ($c->has('ini.log.string_message_format')) {
return $c->get('ini.log.string_message_format');
}
return '%level% %tag%[%datetime%] %message%';
}),
'Piwik\Translation\Loader\LoaderInterface' => DI\object('Piwik\Translation\Loader\LoaderCache')
->constructor(DI\link('Piwik\Translation\Loader\JsonFileLoader')),
);
|