ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 '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 }
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 77 of file FluentdFormatter.php.

78 {
79 $message = '';
80 foreach ($records as $record) {
81 $message .= $this->format($record);
82 }
83
84 return $message;
85 }
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: