ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Formatter\MongoDBFormatter Class Reference

Formats a record for use with the MongoDBHandler. More...

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

Public Member Functions

 __construct ($maxNestingLevel=3, $exceptionTraceAsString=true)
 
 format (array $record)
 Formats a log record.
Parameters
array$recordA record to format
Returns
mixed The formatted record
More...
 
 formatBatch (array $records)
 Formats a set of log records.
Parameters
array$recordsA set of records to format
Returns
mixed The formatted set of records
More...
 
 format (array $record)
 Formats a log record. More...
 
 formatBatch (array $records)
 Formats a set of log records. More...
 

Protected Member Functions

 formatArray (array $record, $nestingLevel=0)
 
 formatObject ($value, $nestingLevel)
 
 formatException (\Exception $exception, $nestingLevel)
 
 formatDate (\DateTime $value, $nestingLevel)
 

Private Attributes

 $exceptionTraceAsString
 
 $maxNestingLevel
 

Detailed Description

Formats a record for use with the MongoDBHandler.

Author
Florian Plattner me@fl.nosp@m.oria.nosp@m.nplat.nosp@m.tner.nosp@m..de

Definition at line 19 of file MongoDBFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Formatter\MongoDBFormatter::__construct (   $maxNestingLevel = 3,
  $exceptionTraceAsString = true 
)
Parameters
int$maxNestingLevel0 means infinite nesting, the $record itself is level 1, $record['context'] is 2
bool$exceptionTraceAsStringset to false to log exception traces as a sub documents instead of strings

Definition at line 28 of file MongoDBFormatter.php.

29 {
30 $this->maxNestingLevel = max($maxNestingLevel, 0);
31 $this->exceptionTraceAsString = (bool) $exceptionTraceAsString;
32 }

References Monolog\Formatter\MongoDBFormatter\$exceptionTraceAsString, and Monolog\Formatter\MongoDBFormatter\$maxNestingLevel.

Member Function Documentation

◆ format()

Monolog\Formatter\MongoDBFormatter::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 37 of file MongoDBFormatter.php.

38 {
39 return $this->formatArray($record);
40 }
formatArray(array $record, $nestingLevel=0)

References Monolog\Formatter\MongoDBFormatter\formatArray().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatArray()

Monolog\Formatter\MongoDBFormatter::formatArray ( array  $record,
  $nestingLevel = 0 
)
protected

Definition at line 54 of file MongoDBFormatter.php.

55 {
56 if ($this->maxNestingLevel == 0 || $nestingLevel <= $this->maxNestingLevel) {
57 foreach ($record as $name => $value) {
58 if ($value instanceof \DateTime) {
59 $record[$name] = $this->formatDate($value, $nestingLevel + 1);
60 } elseif ($value instanceof \Exception) {
61 $record[$name] = $this->formatException($value, $nestingLevel + 1);
62 } elseif (is_array($value)) {
63 $record[$name] = $this->formatArray($value, $nestingLevel + 1);
64 } elseif (is_object($value)) {
65 $record[$name] = $this->formatObject($value, $nestingLevel + 1);
66 }
67 }
68 } else {
69 $record = '[...]';
70 }
71
72 return $record;
73 }
formatException(\Exception $exception, $nestingLevel)
formatDate(\DateTime $value, $nestingLevel)
formatObject($value, $nestingLevel)

References Monolog\Formatter\MongoDBFormatter\formatArray(), Monolog\Formatter\MongoDBFormatter\formatDate(), Monolog\Formatter\MongoDBFormatter\formatException(), and Monolog\Formatter\MongoDBFormatter\formatObject().

Referenced by Monolog\Formatter\MongoDBFormatter\format(), Monolog\Formatter\MongoDBFormatter\formatArray(), Monolog\Formatter\MongoDBFormatter\formatException(), and Monolog\Formatter\MongoDBFormatter\formatObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatBatch()

Monolog\Formatter\MongoDBFormatter::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 45 of file MongoDBFormatter.php.

46 {
47 foreach ($records as $key => $record) {
48 $records[$key] = $this->format($record);
49 }
50
51 return $records;
52 }
format(array $record)
Formats a log record.mixed The formatted record
$records
Definition: simple_test.php:17

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

+ Here is the call graph for this function:

◆ formatDate()

Monolog\Formatter\MongoDBFormatter::formatDate ( \DateTime  $value,
  $nestingLevel 
)
protected

Definition at line 101 of file MongoDBFormatter.php.

102 {
103 return new \MongoDate($value->getTimestamp());
104 }

Referenced by Monolog\Formatter\MongoDBFormatter\formatArray().

+ Here is the caller graph for this function:

◆ formatException()

Monolog\Formatter\MongoDBFormatter::formatException ( \Exception  $exception,
  $nestingLevel 
)
protected

Definition at line 83 of file MongoDBFormatter.php.

84 {
85 $formattedException = array(
86 'class' => get_class($exception),
87 'message' => $exception->getMessage(),
88 'code' => $exception->getCode(),
89 'file' => $exception->getFile() . ':' . $exception->getLine(),
90 );
91
92 if ($this->exceptionTraceAsString === true) {
93 $formattedException['trace'] = $exception->getTraceAsString();
94 } else {
95 $formattedException['trace'] = $exception->getTrace();
96 }
97
98 return $this->formatArray($formattedException, $nestingLevel);
99 }

References Monolog\Formatter\MongoDBFormatter\formatArray().

Referenced by Monolog\Formatter\MongoDBFormatter\formatArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatObject()

Monolog\Formatter\MongoDBFormatter::formatObject (   $value,
  $nestingLevel 
)
protected

Definition at line 75 of file MongoDBFormatter.php.

76 {
77 $objectVars = get_object_vars($value);
78 $objectVars['class'] = get_class($value);
79
80 return $this->formatArray($objectVars, $nestingLevel);
81 }

References Monolog\Formatter\MongoDBFormatter\formatArray().

Referenced by Monolog\Formatter\MongoDBFormatter\formatArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $exceptionTraceAsString

Monolog\Formatter\MongoDBFormatter::$exceptionTraceAsString
private

Definition at line 21 of file MongoDBFormatter.php.

Referenced by Monolog\Formatter\MongoDBFormatter\__construct().

◆ $maxNestingLevel

Monolog\Formatter\MongoDBFormatter::$maxNestingLevel
private

Definition at line 22 of file MongoDBFormatter.php.

Referenced by Monolog\Formatter\MongoDBFormatter\__construct().


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