ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Formatter\FluentdFormatter Class Reference

Class FluentdFormatter. More...

+ Inheritance diagram for Monolog\Formatter\FluentdFormatter:
+ Collaboration diagram for Monolog\Formatter\FluentdFormatter:

Public Member Functions

 __construct ($levelTag=false)
 
 isUsingLevelsInTag ()
 
 format (array $record)
 Formats a log record. More...
 
 formatBatch (array $records)
 Formats a set of log records. More...
 
 format (array $record)
 Formats a log record. More...
 
 formatBatch (array $records)
 Formats a set of log records. More...
 

Protected Attributes

 $levelTag = false
 

Detailed Description

Class FluentdFormatter.

Serializes a log message to Fluentd unix socket protocol

Fluentd config:

<source> type unix path /var/run/td-agent/td-agent.sock </source>

Monolog setup:

$logger = new Monolog\Logger('fluent.tag'); $fluentHandler = new Monolog\Handler\SocketHandler('unix:///var/run/td-agent/td-agent.sock'); $fluentHandler->setFormatter(new Monolog\Formatter\FluentdFormatter()); $logger->pushHandler($fluentHandler);

Author
Andrius Putna fordn.nosp@m.ox@g.nosp@m.mail..nosp@m.com

Definition at line 35 of file FluentdFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Formatter\FluentdFormatter::__construct (   $levelTag = false)

Definition at line 42 of file FluentdFormatter.php.

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 }

References Monolog\Formatter\FluentdFormatter\$levelTag.

Member Function Documentation

◆ format()

Monolog\Formatter\FluentdFormatter::format ( array  $record)

Formats a log record.

Parameters
array$recordA record to format
Returns
mixed The formatted record

Implements Monolog\Formatter\FormatterInterface.

Definition at line 56 of file FluentdFormatter.php.

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 'extra' => $record['extra'],
66 );
67
68 if (!$this->levelTag) {
69 $message['level'] = $record['level'];
70 $message['level_name'] = $record['level_name'];
71 }
72
73 return json_encode(array($tag, $record['datetime']->getTimestamp(), $message));
74 }
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
catch(Exception $e) $message

References $message, and $tag.

Referenced by Monolog\Formatter\FluentdFormatter\formatBatch().

+ Here is the caller graph for this function:

◆ formatBatch()

Monolog\Formatter\FluentdFormatter::formatBatch ( array  $records)

Formats a set of log records.

Parameters
array$recordsA set of records to format
Returns
mixed The formatted set of records

Implements Monolog\Formatter\FormatterInterface.

Definition at line 76 of file FluentdFormatter.php.

77 {
78 $message = '';
79 foreach ($records as $record) {
80 $message .= $this->format($record);
81 }
82
83 return $message;
84 }
format(array $record)
Formats a log record.
$records
Definition: simple_test.php:22

References $message, $records, and Monolog\Formatter\FluentdFormatter\format().

+ Here is the call graph for this function:

◆ isUsingLevelsInTag()

Monolog\Formatter\FluentdFormatter::isUsingLevelsInTag ( )

Definition at line 51 of file FluentdFormatter.php.

52 {
53 return $this->levelTag;
54 }

References Monolog\Formatter\FluentdFormatter\$levelTag.

Field Documentation

◆ $levelTag

Monolog\Formatter\FluentdFormatter::$levelTag = false
protected

The documentation for this class was generated from the following file: