ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FluentdFormatter.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
36{
40 protected $levelTag = false;
41
42 public function __construct($levelTag = false)
43 {
44 if (!function_exists('json_encode')) {
45 throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s FluentdUnixFormatter');
46 }
47
48 $this->levelTag = (bool) $levelTag;
49 }
50
51 public function isUsingLevelsInTag()
52 {
53 return $this->levelTag;
54 }
55
56 public function format(array $record)
57 {
58 $tag = $record['channel'];
59 if ($this->levelTag) {
60 $tag .= '.' . strtolower($record['level_name']);
61 }
62
63 $message = array(
64 'message' => $record['message'],
65 'context' => $record['context'],
66 'extra' => $record['extra'],
67 );
68
69 if (!$this->levelTag) {
70 $message['level'] = $record['level'];
71 $message['level_name'] = $record['level_name'];
72 }
73
74 return json_encode(array($tag, $record['datetime']->getTimestamp(), $message));
75 }
76
77 public function formatBatch(array $records)
78 {
79 $message = '';
80 foreach ($records as $record) {
81 $message .= $this->format($record);
82 }
83
84 return $message;
85 }
86}
An exception for terminatinating execution or to throw for unit testing.
formatBatch(array $records)
Formats a set of log records.
format(array $record)
Formats a log record.
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
catch(Exception $e) $message
$records
Definition: simple_test.php:22