ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
JsonFormatter.php
Go to the documentation of this file.
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
12namespace Monolog\Formatter;
13
22{
23 const BATCH_MODE_JSON = 1;
25
26 protected $batchMode;
27 protected $appendNewline;
28
32 public function __construct($batchMode = self::BATCH_MODE_JSON, $appendNewline = true)
33 {
34 $this->batchMode = $batchMode;
35 $this->appendNewline = $appendNewline;
36 }
37
47 public function getBatchMode()
48 {
49 return $this->batchMode;
50 }
51
57 public function isAppendingNewlines()
58 {
60 }
61
65 public function format(array $record)
66 {
67 return json_encode($record) . ($this->appendNewline ? "\n" : '');
68 }
69
73 public function formatBatch(array $records)
74 {
75 switch ($this->batchMode) {
76 case static::BATCH_MODE_NEWLINES:
77 return $this->formatBatchNewlines($records);
78
79 case static::BATCH_MODE_JSON:
80 default:
81 return $this->formatBatchJson($records);
82 }
83 }
84
91 protected function formatBatchJson(array $records)
92 {
93 return json_encode($records);
94 }
95
103 protected function formatBatchNewlines(array $records)
104 {
105 $instance = $this;
106
107 $oldNewline = $this->appendNewline;
108 $this->appendNewline = false;
109 array_walk($records, function (&$value, $key) use ($instance) {
110 $value = $instance->format($value);
111 });
112 $this->appendNewline = $oldNewline;
113
114 return implode("\n", $records);
115 }
116}
Encodes whatever record data is passed to it as json.
isAppendingNewlines()
True if newlines are appended to every formatted record.
formatBatch(array $records)
{Formats a set of log records.mixed The formatted set of records}
format(array $record)
{Formats a log record.mixed The formatted record}
formatBatchNewlines(array $records)
Use new lines to separate records instead of a JSON-encoded array.
getBatchMode()
The batch mode option configures the formatting style for multiple records.
formatBatchJson(array $records)
Return a JSON-encoded array of records.
__construct($batchMode=self::BATCH_MODE_JSON, $appendNewline=true)
$records
Definition: simple_test.php:17