|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Logger\Handlers\JsonFormatter |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link http://github.com/appserver-io/logger |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Logger\Formatters; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A formatter that encodes the formatted message with PHP json_encode() method. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Tim Wagner <[email protected]> |
|
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link http://github.com/appserver-io/logger |
|
30
|
|
|
* @link http://www.appserver.io |
|
31
|
|
|
* @see http://php.net/manual/en/function.sprintf.php |
|
32
|
|
|
*/ |
|
33
|
|
|
class JsonFormatter extends StandardFormatter |
|
34
|
|
|
{ |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Initializes the handler instance with channel name and log level. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string|null $messageFormat The message format, MUST be valid for sprintf |
|
40
|
|
|
* @param string|null $dateFormat The date format, valid for PHP date() function |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($messageFormat = null, $dateFormat = null) |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
// initialize message and date format |
|
46
|
|
|
if ($messageFormat == null) { |
|
|
|
|
|
|
47
|
|
|
$messageFormat = '{ "timestamp": "%s", "id": "%s", "level" : "%s", "message": "%s", "context": %s }'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// pass variables to parent |
|
51
|
|
|
parent::__construct($messageFormat, $dateFormat); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|