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

38  {
39  $this->format = $format ?: static::SIMPLE_FORMAT;
42  parent::__construct($dateFormat);
43  }
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 53 of file LineFormatter.php.

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

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

◆ convertToString()

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

Definition at line 144 of file LineFormatter.php.

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

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

145  {
146  if (null === $data || is_bool($data)) {
147  return var_export($data, true);
148  }
149 
150  if (is_scalar($data)) {
151  return (string) $data;
152  }
153 
154  if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
155  return $this->toJson($data, true);
156  }
157 
158  return str_replace('\\/', '/', @json_encode($data));
159  }
toJson($data, $ignoreErrors=false)
Return the JSON representation of a value.
+ 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 66 of file LineFormatter.php.

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

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

67  {
68  $vars = parent::format($record);
69 
71 
72  foreach ($vars['extra'] as $var => $val) {
73  if (false !== strpos($output, '%extra.'.$var.'%')) {
74  $output = str_replace('%extra.'.$var.'%', $this->stringify($val), $output);
75  unset($vars['extra'][$var]);
76  }
77  }
78 
79  foreach ($vars['context'] as $var => $val) {
80  if (false !== strpos($output, '%context.'.$var.'%')) {
81  $output = str_replace('%context.'.$var.'%', $this->stringify($val), $output);
82  unset($vars['context'][$var]);
83  }
84  }
85 
86  if ($this->ignoreEmptyContextAndExtra) {
87  if (empty($vars['context'])) {
88  unset($vars['context']);
89  $output = str_replace('%context%', '', $output);
90  }
91 
92  if (empty($vars['extra'])) {
93  unset($vars['extra']);
94  $output = str_replace('%extra%', '', $output);
95  }
96  }
97 
98  foreach ($vars as $var => $val) {
99  if (false !== strpos($output, '%'.$var.'%')) {
100  $output = str_replace('%'.$var.'%', $this->stringify($val), $output);
101  }
102  }
103 
104  return $output;
105  }
ignoreEmptyContextAndExtra($ignore=true)
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Write to Excel2007 format
+ 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 107 of file LineFormatter.php.

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

108  {
109  $message = '';
110  foreach ($records as $record) {
111  $message .= $this->format($record);
112  }
113 
114  return $message;
115  }
$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 58 of file LineFormatter.php.

References $ignore.

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

59  {
61  }
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 45 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\allowInlineLineBreaks().

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

46  {
47  $this->includeStacktraces = $include;
48  if ($this->includeStacktraces) {
49  $this->allowInlineLineBreaks = true;
50  }
51  }
+ 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 122 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\includeStacktraces().

123  {
124  // TODO 2.0 only check for Throwable
125  if (!$e instanceof \Exception && !$e instanceof \Throwable) {
126  throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
127  }
128 
129  $previousText = '';
130  if ($previous = $e->getPrevious()) {
131  do {
132  $previousText .= ', '.get_class($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
133  } while ($previous = $previous->getPrevious());
134  }
135 
136  $str = '[object] ('.get_class($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
137  if ($this->includeStacktraces) {
138  $str .= "\n[stacktrace]\n".$e->getTraceAsString();
139  }
140 
141  return $str;
142  }
+ Here is the call graph for this function:

◆ replaceNewlines()

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

Definition at line 161 of file LineFormatter.php.

References Monolog\Formatter\LineFormatter\allowInlineLineBreaks(), and array.

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

162  {
163  if ($this->allowInlineLineBreaks) {
164  return $str;
165  }
166 
167  return str_replace(array("\r\n", "\r", "\n"), ' ', $str);
168  }
Create styles array
The data for the language used.
+ 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 117 of file LineFormatter.php.

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

118  {
119  return $this->replaceNewlines($this->convertToString($value));
120  }
+ Here is the call graph for this function:

Field Documentation

◆ $allowInlineLineBreaks

Monolog\Formatter\LineFormatter::$allowInlineLineBreaks
protected

Definition at line 27 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 28 of file LineFormatter.php.

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

◆ $includeStacktraces

Monolog\Formatter\LineFormatter::$includeStacktraces
protected

Definition at line 29 of file LineFormatter.php.

◆ SIMPLE_FORMAT

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

Definition at line 24 of file LineFormatter.php.


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