blob: 4b778f858ac622e9f5961dfc1d44c04a456fe001 (
plain)
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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Log\Formatter;
use Piwik\Log;
/**
* Formats a log message into a single line of text.
*/
class LineMessageFormatter extends Formatter
{
/**
* The log message format string that turns a tag name, date-time and message into
* one string to log.
*
* @var string
*/
private $logMessageFormat;
public function __construct($logMessageFormat)
{
$this->logMessageFormat = $logMessageFormat;
}
public function format(array $record, Log $logger)
{
if (! is_string($record['message'])) {
throw new \InvalidArgumentException('Trying to log a message that is not a string');
}
$record['message'] = str_replace(
array("%tag%", "%message%", "%datetime%", "%level%"),
array($record['extra']['class'], trim($record['message']), $record['time']->format('Y-m-d H:i:s'), $record['level_name']),
$this->logMessageFormat
);
return $this->next($record, $logger);
}
}
|