63 parent::__construct(
'U.u');
75 public function format(array $record)
77 $record = parent::format($record);
79 if (!isset($record[
'datetime'], $record[
'message'], $record[
'level'])) {
80 throw new \InvalidArgumentException(
'The record should at least contain datetime, message and level keys, '.var_export($record,
true).
' given');
85 ->setTimestamp($record[
'datetime'])
86 ->setShortMessage((
string) $record[
'message'])
87 ->setHost($this->systemName)
88 ->setLevel($this->logLevels[$record[
'level']]);
91 $len = 200 + strlen((
string) $record[
'message']) + strlen($this->systemName);
93 if ($len > $this->maxLength) {
94 $message->setShortMessage(substr($record[
'message'], 0, $this->maxLength));
97 if (isset($record[
'channel'])) {
98 $message->setFacility($record[
'channel']);
100 if (isset($record[
'extra'][
'line'])) {
101 $message->setLine($record[
'extra'][
'line']);
102 unset($record[
'extra'][
'line']);
104 if (isset($record[
'extra'][
'file'])) {
105 $message->setFile($record[
'extra'][
'file']);
106 unset($record[
'extra'][
'file']);
109 foreach ($record[
'extra'] as
$key => $val) {
110 $val = is_scalar($val) || null === $val ? $val : $this->
toJson($val);
111 $len = strlen($this->extraPrefix .
$key . $val);
112 if ($len > $this->maxLength) {
113 $message->setAdditional($this->extraPrefix .
$key, substr($val, 0, $this->maxLength));
116 $message->setAdditional($this->extraPrefix .
$key, $val);
119 foreach ($record[
'context'] as
$key => $val) {
120 $val = is_scalar($val) || null === $val ? $val : $this->
toJson($val);
121 $len = strlen($this->contextPrefix .
$key . $val);
122 if ($len > $this->maxLength) {
123 $message->setAdditional($this->contextPrefix .
$key, substr($val, 0, $this->maxLength));
126 $message->setAdditional($this->contextPrefix .
$key, $val);
129 if (null ===
$message->getFile() && isset($record[
'context'][
'exception'][
'file'])) {
130 if (preg_match(
"/^(.+):([0-9]+)$/", $record[
'context'][
'exception'][
'file'], $matches)) {
const NOTICE
Uncommon events.
const DEBUG
Detailed debug information.
const ERROR
Runtime errors.
catch(Exception $e) $message
const WARNING
Exceptional occurrences that are not errors.
const EMERGENCY
Urgent alert.
const CRITICAL
Critical conditions.
const ALERT
Action must be taken immediately.
const INFO
Interesting events.