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

Formats incoming records into a one-line string. More...

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

Public Member Functions

 __construct ($format=null, $dateFormat=null, $allowInlineLineBreaks=false, $ignoreEmptyContextAndExtra=false)
 
 includeStacktraces ($include=true)
 
 allowInlineLineBreaks ($allow=true)
 
 ignoreEmptyContextAndExtra ($ignore=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. More...
 
 stringify ($value)
 
- Public Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 __construct ($dateFormat=null)
 
 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...
 

Data Fields

const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
 
- Data Fields inherited from Monolog\Formatter\NormalizerFormatter
const SIMPLE_DATE = "Y-m-d H:i:s"
 

Protected Member Functions

 normalizeException (Exception $e)
 
 convertToString ($data)
 
 replaceNewlines ($str)
 
- Protected Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 normalize ($data)
 
 normalizeException (Exception $e)
 
 toJson ($data, $ignoreErrors=false)
 

Protected Attributes

 $format
 
 $allowInlineLineBreaks
 
 $ignoreEmptyContextAndExtra
 
 $includeStacktraces
 
- Protected Attributes inherited from Monolog\Formatter\NormalizerFormatter
 $dateFormat
 

Detailed Description

Formats incoming records into a one-line string.

This is especially useful for logging to files

Author
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be
Christophe Coevoet stof@.nosp@m.notk.nosp@m..org

Definition at line 24 of file LineFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Formatter\LineFormatter::__construct (   $format = null,
  $dateFormat = null,
  $allowInlineLineBreaks = false,
  $ignoreEmptyContextAndExtra = false 
)
Parameters
string$formatThe format of the message
string$dateFormatThe format of the timestamp: one supported by DateTime::format
bool$allowInlineLineBreaksWhether to allow inline line breaks in log entries
bool$ignoreEmptyContextAndExtra

Definition at line 39 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\$allowInlineLineBreaks, Monolog\Formatter\NormalizerFormatter\$dateFormat, Monolog\Formatter\LineFormatter\$format, Monolog\Formatter\LineFormatter\$ignoreEmptyContextAndExtra, Monolog\Formatter\LineFormatter\allowInlineLineBreaks(), Monolog\Formatter\LineFormatter\format(), and Monolog\Formatter\LineFormatter\ignoreEmptyContextAndExtra().

40  {
41  $this->format = $format ?: static::SIMPLE_FORMAT;
44  parent::__construct($dateFormat);
45  }
ignoreEmptyContextAndExtra($ignore=true)
format(array $record)
{Formats a log record.A record to format mixed The formatted record}
+ Here is the call graph for this function:

Member Function Documentation

◆ allowInlineLineBreaks()

Monolog\Formatter\LineFormatter::allowInlineLineBreaks (   $allow = true)

Definition at line 55 of file LineFormatter.php.

Referenced by Monolog\Formatter\LineFormatter\__construct(), Monolog\Formatter\LineFormatter\includeStacktraces(), and Monolog\Formatter\LineFormatter\replaceNewlines().

56  {
57  $this->allowInlineLineBreaks = $allow;
58  }
+ Here is the caller graph for this function:

◆ convertToString()

Monolog\Formatter\LineFormatter::convertToString (   $data)
protected

Definition at line 134 of file LineFormatter.php.

References $data, and Monolog\Formatter\NormalizerFormatter\toJson().

Referenced by Monolog\Formatter\LineFormatter\stringify().

135  {
136  if (null === $data || is_bool($data)) {
137  return var_export($data, true);
138  }
139 
140  if (is_scalar($data)) {
141  return (string) $data;
142  }
143 
144  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
145  return $this->toJson($data, true);
146  }
147 
148  return str_replace('\\/', '/', @json_encode($data));
149  }
$data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format()

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

References Monolog\Formatter\LineFormatter\$format, and Monolog\Formatter\LineFormatter\ignoreEmptyContextAndExtra().

Referenced by Monolog\Formatter\LineFormatter\__construct(), and Monolog\Formatter\LineFormatter\formatBatch().

69  {
70  $vars = parent::format($record);
71 
72  $output = $this->format;
73 
74  foreach ($vars['extra'] as $var => $val) {
75  if (false !== strpos($output, '%extra.'.$var.'%')) {
76  $output = str_replace('%extra.'.$var.'%', $this->stringify($val), $output);
77  unset($vars['extra'][$var]);
78  }
79  }
80 
81  if ($this->ignoreEmptyContextAndExtra) {
82  if (empty($vars['context'])) {
83  unset($vars['context']);
84  $output = str_replace('%context%', '', $output);
85  }
86 
87  if (empty($vars['extra'])) {
88  unset($vars['extra']);
89  $output = str_replace('%extra%', '', $output);
90  }
91  }
92 
93  foreach ($vars as $var => $val) {
94  if (false !== strpos($output, '%'.$var.'%')) {
95  $output = str_replace('%'.$var.'%', $this->stringify($val), $output);
96  }
97  }
98 
99  return $output;
100  }
ignoreEmptyContextAndExtra($ignore=true)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatBatch()

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

References Monolog\Formatter\LineFormatter\format().

103  {
104  $message = '';
105  foreach ($records as $record) {
106  $message .= $this->format($record);
107  }
108 
109  return $message;
110  }
$records
Definition: simple_test.php:17
format(array $record)
{Formats a log record.A record to format mixed The formatted record}
+ Here is the call graph for this function:

◆ ignoreEmptyContextAndExtra()

Monolog\Formatter\LineFormatter::ignoreEmptyContextAndExtra (   $ignore = true)

Definition at line 60 of file LineFormatter.php.

References $ignore.

Referenced by Monolog\Formatter\LineFormatter\__construct(), and Monolog\Formatter\LineFormatter\format().

61  {
63  }
while(false !==( $line=fgets( $in))) if(! $columns) $ignore
Definition: Utf8Test.php:64
ignoreEmptyContextAndExtra($ignore=true)
+ Here is the caller graph for this function:

◆ includeStacktraces()

Monolog\Formatter\LineFormatter::includeStacktraces (   $include = true)

Definition at line 47 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\allowInlineLineBreaks().

Referenced by Monolog\Formatter\LineFormatter\normalizeException().

48  {
49  $this->includeStacktraces = $include;
50  if ($this->includeStacktraces) {
51  $this->allowInlineLineBreaks = true;
52  }
53  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizeException()

Monolog\Formatter\LineFormatter::normalizeException ( Exception  $e)
protected

Definition at line 117 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\includeStacktraces().

118  {
119  $previousText = '';
120  if ($previous = $e->getPrevious()) {
121  do {
122  $previousText .= ', '.get_class($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
123  } while ($previous = $previous->getPrevious());
124  }
125 
126  $str = '[object] ('.get_class($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
127  if ($this->includeStacktraces) {
128  $str .= "\n[stacktrace]\n".$e->getTraceAsString();
129  }
130 
131  return $str;
132  }
+ Here is the call graph for this function:

◆ replaceNewlines()

Monolog\Formatter\LineFormatter::replaceNewlines (   $str)
protected

Definition at line 151 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\allowInlineLineBreaks().

Referenced by Monolog\Formatter\LineFormatter\stringify().

152  {
153  if ($this->allowInlineLineBreaks) {
154  return $str;
155  }
156 
157  return str_replace(array("\r\n", "\r", "\n"), ' ', $str);
158  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stringify()

Monolog\Formatter\LineFormatter::stringify (   $value)

Definition at line 112 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\convertToString(), and Monolog\Formatter\LineFormatter\replaceNewlines().

113  {
114  return $this->replaceNewlines($this->convertToString($value));
115  }
+ Here is the call graph for this function:

Field Documentation

◆ $allowInlineLineBreaks

Monolog\Formatter\LineFormatter::$allowInlineLineBreaks
protected

Definition at line 29 of file LineFormatter.php.

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

◆ $format

Monolog\Formatter\LineFormatter::$format
protected

◆ $ignoreEmptyContextAndExtra

Monolog\Formatter\LineFormatter::$ignoreEmptyContextAndExtra
protected

Definition at line 30 of file LineFormatter.php.

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

◆ $includeStacktraces

Monolog\Formatter\LineFormatter::$includeStacktraces
protected

Definition at line 31 of file LineFormatter.php.

◆ SIMPLE_FORMAT

const Monolog\Formatter\LineFormatter::SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"

Definition at line 26 of file LineFormatter.php.


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