ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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.

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

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

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.

References Monolog\Formatter\MongoDBFormatter\formatArray().

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

38  {
39  return $this->formatArray($record);
40  }
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 54 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().

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  }
if($format !==null) $name
Definition: metadata.php:146
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 45 of file MongoDBFormatter.php.

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

46  {
47  foreach ($records as $key => $record) {
48  $records[$key] = $this->format($record);
49  }
50 
51  return $records;
52  }
$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 101 of file MongoDBFormatter.php.

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

102  {
103  return new \MongoDate($value->getTimestamp());
104  }
+ 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.

References array, and Monolog\Formatter\MongoDBFormatter\formatArray().

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

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  }
Create styles array
The data for the language used.
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 75 of file MongoDBFormatter.php.

References Monolog\Formatter\MongoDBFormatter\formatArray().

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

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