blob: 9d027f588683d3796c5a8d0a63a9ced4a3073a9d (
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
|
<?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\Common;
use Piwik\Log;
/**
* Adds a unique "request id" to the log message to follow log entries for each HTTP request.
*/
class AddRequestIdFormatter extends Formatter
{
public function format(array $record)
{
static $currentRequestKey;
if (empty($currentRequestKey)) {
$currentRequestKey = substr(Common::generateUniqId(), 0, 5);
}
$record = $this->next($record);
if (! is_string($record['message'])) {
return $record;
}
// Decorate the error message with the "request id"
if (!defined('PIWIK_TEST_MODE')) {
$record['message'] = '[' . $currentRequestKey . '] ' . $record['message'];
}
return $record;
}
}
|