ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 

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 21 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 30 of file MongoDBFormatter.php.

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

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

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 39 of file MongoDBFormatter.php.

References Monolog\Formatter\MongoDBFormatter\formatArray().

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

40  {
41  return $this->formatArray($record);
42  }
formatArray(array $record, $nestingLevel=0)
+ 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 56 of file MongoDBFormatter.php.

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

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

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

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

48  {
49  foreach ($records as $key => $record) {
50  $records[$key] = $this->format($record);
51  }
52 
53  return $records;
54  }
$records
Definition: simple_test.php:22
format(array $record)
Formats a log record.A record to format mixed The formatted record
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ formatDate()

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

Definition at line 103 of file MongoDBFormatter.php.

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

104  {
105  return new \MongoDate($value->getTimestamp());
106  }
+ Here is the caller graph for this function:

◆ formatException()

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

Definition at line 85 of file MongoDBFormatter.php.

References Monolog\Formatter\MongoDBFormatter\formatArray(), and Monolog\Utils\getClass().

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

86  {
87  $formattedException = array(
88  'class' => Utils::getClass($exception),
89  'message' => $exception->getMessage(),
90  'code' => $exception->getCode(),
91  'file' => $exception->getFile() . ':' . $exception->getLine(),
92  );
93 
94  if ($this->exceptionTraceAsString === true) {
95  $formattedException['trace'] = $exception->getTraceAsString();
96  } else {
97  $formattedException['trace'] = $exception->getTrace();
98  }
99 
100  return $this->formatArray($formattedException, $nestingLevel);
101  }
static getClass($object)
Definition: Utils.php:19
formatArray(array $record, $nestingLevel=0)
+ 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 77 of file MongoDBFormatter.php.

References Monolog\Formatter\MongoDBFormatter\formatArray(), and Monolog\Utils\getClass().

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

78  {
79  $objectVars = get_object_vars($value);
80  $objectVars['class'] = Utils::getClass($value);
81 
82  return $this->formatArray($objectVars, $nestingLevel);
83  }
static getClass($object)
Definition: Utils.php:19
formatArray(array $record, $nestingLevel=0)
+ 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 23 of file MongoDBFormatter.php.

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

◆ $maxNestingLevel

Monolog\Formatter\MongoDBFormatter::$maxNestingLevel
private

Definition at line 24 of file MongoDBFormatter.php.

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


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