|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Monolog package. |
|
|
5 |
* |
|
|
6 |
* (c) Jordi Boggiano <j.boggiano@seld.be> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Monolog\Formatter; |
|
|
13 |
|
|
|
14 |
use Monolog\Logger; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* Encodes whatever record data is passed to it as json |
|
|
18 |
* |
|
|
19 |
* This can be useful to log to databases or remote APIs |
|
|
20 |
* |
|
|
21 |
* @author Jordi Boggiano <j.boggiano@seld.be> |
|
|
22 |
*/ |
|
|
23 |
class JsonFormatter implements FormatterInterface |
|
|
24 |
{ |
|
|
25 |
/** |
|
|
26 |
* {@inheritdoc} |
|
|
27 |
*/ |
|
|
28 |
public function format(array $record) |
|
|
29 |
{ |
|
|
30 |
return json_encode($record); |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* {@inheritdoc} |
|
|
35 |
*/ |
|
|
36 |
public function formatBatch(array $records) |
|
|
37 |
{ |
|
|
38 |
return json_encode($records); |
|
|
39 |
} |
|
|
40 |
} |