ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
 detectAndCleanUtf8 (&$data)
 Detect invalid UTF-8 string characters and convert to valid UTF-8. 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 ($e)
 
 convertToString ($data)
 
 replaceNewlines ($str)
 
- Protected Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 normalize ($data, $depth=0)
 
 normalizeException ($e)
 
 toJson ($data, $ignoreErrors=false)
 Return the JSON representation of a value. More...
 

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 152 of file LineFormatter.php.

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

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

153  {
154  if (null === $data || is_bool($data)) {
155  return var_export($data, true);
156  }
157 
158  if (is_scalar($data)) {
159  return (string) $data;
160  }
161 
162  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
163  return $this->toJson($data, true);
164  }
165 
166  return str_replace('\\/', '/', @json_encode($data));
167  }
toJson($data, $ignoreErrors=false)
Return the JSON representation of a value.
$data
Definition: bench.php:6
+ 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, Sabre\VObject\$output, and Monolog\Formatter\LineFormatter\ignoreEmptyContextAndExtra().

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

69  {
70  $vars = parent::format($record);
71 
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 
82  foreach ($vars['context'] as $var => $val) {
83  if (false !== strpos($output, '%context.'.$var.'%')) {
84  $output = str_replace('%context.'.$var.'%', $this->stringify($val), $output);
85  unset($vars['context'][$var]);
86  }
87  }
88 
89  if ($this->ignoreEmptyContextAndExtra) {
90  if (empty($vars['context'])) {
91  unset($vars['context']);
92  $output = str_replace('%context%', '', $output);
93  }
94 
95  if (empty($vars['extra'])) {
96  unset($vars['extra']);
97  $output = str_replace('%extra%', '', $output);
98  }
99  }
100 
101  foreach ($vars as $var => $val) {
102  if (false !== strpos($output, '%'.$var.'%')) {
103  $output = str_replace('%'.$var.'%', $this->stringify($val), $output);
104  }
105  }
106 
107  // remove leftover %extra.xxx% and %context.xxx% if any
108  if (false !== strpos($output, '%')) {
109  $output = preg_replace('/%(?:extra|context)\..+?%/', '', $output);
110  }
111 
112  return $output;
113  }
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 115 of file LineFormatter.php.

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

116  {
117  $message = '';
118  foreach ($records as $record) {
119  $message .= $this->format($record);
120  }
121 
122  return $message;
123  }
$records
Definition: simple_test.php:22
catch(Exception $e) $message
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  }
ignoreEmptyContextAndExtra($ignore=true)
while(false !==($line=fgets($in))) if(! $columns) $ignore
Definition: Utf8Test.php:63
+ 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 (   $e)
protected

Definition at line 130 of file LineFormatter.php.

References Monolog\Utils\getClass(), and Monolog\Formatter\LineFormatter\includeStacktraces().

131  {
132  // TODO 2.0 only check for Throwable
133  if (!$e instanceof \Exception && !$e instanceof \Throwable) {
134  throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Utils::getClass($e));
135  }
136 
137  $previousText = '';
138  if ($previous = $e->getPrevious()) {
139  do {
140  $previousText .= ', '.Utils::getClass($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
141  } while ($previous = $previous->getPrevious());
142  }
143 
144  $str = '[object] ('.Utils::getClass($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
145  if ($this->includeStacktraces) {
146  $str .= "\n[stacktrace]\n".$e->getTraceAsString()."\n";
147  }
148 
149  return $str;
150  }
static getClass($object)
Definition: Utils.php:19
+ Here is the call graph for this function:

◆ replaceNewlines()

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

Definition at line 169 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\allowInlineLineBreaks().

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

170  {
171  if ($this->allowInlineLineBreaks) {
172  if (0 === strpos($str, '{')) {
173  return str_replace(array('\r', '\n'), array("\r", "\n"), $str);
174  }
175 
176  return $str;
177  }
178 
179  return str_replace(array("\r\n", "\r", "\n"), ' ', $str);
180  }
+ 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 125 of file LineFormatter.php.

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

126  {
127  return $this->replaceNewlines($this->convertToString($value));
128  }
+ 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: