mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 08:36:33 +02:00
Added support of objects and arrays as values in LineFormatter. closes #19
This commit is contained in:
@@ -51,16 +51,16 @@ class LineFormatter implements FormatterInterface
|
||||
if (is_array($val)) {
|
||||
$strval = array();
|
||||
foreach ($val as $subvar => $subval) {
|
||||
$strval[] = $subvar.': '.$subval;
|
||||
$strval[] = $subvar.': '.$this->convertToString($subval);
|
||||
}
|
||||
$replacement = $strval ? $var.'('.implode(', ', $strval).')' : '';
|
||||
$output = str_replace('%'.$var.'%', $replacement, $output);
|
||||
} else {
|
||||
$output = str_replace('%'.$var.'%', $val, $output);
|
||||
$output = str_replace('%'.$var.'%', $this->convertToString($val), $output);
|
||||
}
|
||||
}
|
||||
foreach ($vars['extra'] as $var => $val) {
|
||||
$output = str_replace('%extra.'.$var.'%', $val, $output);
|
||||
$output = str_replace('%extra.'.$var.'%', $this->convertToString($val), $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
@@ -75,4 +75,13 @@ class LineFormatter implements FormatterInterface
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
private function convertToString($data)
|
||||
{
|
||||
if (is_scalar($data) || (is_object($data) && method_exists($data, '__toString'))) {
|
||||
return (string) $data;
|
||||
}
|
||||
|
||||
return serialize($data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user