/** * @param FormatterInterface $formatter * * @return array */ public function getFormattedLogArray($formatter = null) { $res = []; if ($formatter === null) { $formatter = new LineFormatter(); } foreach ($this->buffer as $record) { $res[] = trim($formatter->format($record)); } return $res; }
/** * {@inheritdoc} */ public function format(array $record) { $record['start_tag'] = ''; $record['end_tag'] = ''; if ($record['level'] >= Logger::ERROR) { $record['start_tag'] = '<error>'; $record['end_tag'] = '</error>'; } elseif ($record['level'] == Logger::FAIL) { $record['start_tag'] = '<fail>'; $record['end_tag'] = '</fail>'; } elseif ($record['level'] >= Logger::WARNING) { $record['start_tag'] = '<info>'; $record['end_tag'] = '</info>'; } elseif ($record['level'] >= Logger::NOTICE) { $record['start_tag'] = '<comment>'; $record['end_tag'] = '</comment>'; } elseif ($record['level'] >= Logger::INFO) { $record['start_tag'] = '<info>'; $record['end_tag'] = '</info>'; } elseif ($record['level'] >= Logger::DEBUG) { $record['start_tag'] = '<comment>'; $record['end_tag'] = '</comment>'; } return parent::format($record); }
/** * {@inheritdoc} */ public function format(array $record) { $tag = strtolower($record['level_name']); $record['start_tag'] = '<' . $tag . '>'; $record['end_tag'] = '</' . $tag . '>'; return parent::format($record); }
/** * {@inheritdoc} */ public function format(array $record) { // Retrieve the line and file if set and remove them from the formatted extra $file = $line = ''; if (isset($record['extra']['file'])) { $file = $record['extra']['file']; unset($record['extra']['file']); } if (isset($record['extra']['line'])) { $line = $record['extra']['line']; unset($record['extra']['line']); } // Format record according with LineFormatter $message = parent::format($record); // Create JSON object describing the appearance of the message in the console $json = json_encode(array( array( 'Type' => $this->logLevels[$record['level']], 'File' => $file, 'Line' => $line, 'Label' => $record['channel'], ), $message, )); // The message itself is a serialization of the above JSON object + it's length return sprintf( '%s|%s|', strlen($json), $json ); }
/** * {@inheritdoc} */ public function format(array $record) { // Get the Color Scheme $colorScheme = $this->getColorScheme(); // Let the parent class to the formatting, yet wrap it in the color linked to the level return $colorScheme->getColorizeString($record['level']) . trim(parent::format($record)) . $colorScheme->getResetString() . "\n"; }
/** * {@inheritdoc} */ public function format(array $record) { $str = parent::format($record); $str = str_replace('%time%', $record['datetime']->format('H:i:s'), $str); $str = str_replace('%csv%', $this->csvify($record['context']), $str); return rtrim($str, $this->delimiter); }
/** * @param array $record * @return mixed|string */ public function format(array $record) { $this->logCounter++; $output = parent::format($record); $output = str_replace('%counter%', $this->logCounter, $output); $output = str_replace('%req-id%', $this->reqId, $output); return $output; }
/** * {@inheritdoc} */ public function format(array $record) { $output = parent::format($record); $output .= PHP_EOL . print_r($_SERVER, true); $output .= PHP_EOL . print_r($_SESSION, true); return $output; //return str_replace('\n', '<br>', $output); }
/** * @param array $record * @return array|mixed|string */ public function format(array $record) { $output = parent::format($record); if ($this->editFormatted) { $output = $this->editFormatted($output); } return $output; }
/** * {@inheritdoc} */ public function format(array $record) { $output = trim(parent::format($record)); if ($this->maxLength !== null && strlen($output) > $this->maxLength) { $output = substr($output, 0, $this->maxLength - 3) . '...'; } return $output; }
/** * Formats a log record. * * @param array $record A record to format * @return mixed The formatted record */ public function format(array $record) { $formatted = parent::format($record); $levelName = strtolower($record['level_name']); $wrapped = sprintf('<%1$s>%2$s</%1$s>', $levelName, $formatted); $result = $this->getOutputFormatter()->format($wrapped); return $result; }
/** * {@inheritdoc} */ public function format(array $record) { // Format record according with LineFormatter $message = parent::format($record); // Create JSON object describing the appearance of the message in the console $json = json_encode(array(array('Type' => $this->logLevels[$record['level']], 'File' => '', 'Line' => ''), $message)); // The message itself is a serialization of the above JSON object + it's length return sprintf('%s|%s|', strlen($json), $json); }
public function format(array $record) { $record['codeInfo'] = ''; if (isset($record['extra']['class']) && isset($record['extra']['function']) && isset($record['extra']['line'])) { $record['codeInfo'] = $record['extra']['class'] . '::' . $record['extra']['function'] . ':' . $record['extra']['line']; } //return parent return parent::format($record); }
/** * @covers ::getDefaultFormatter */ public function testHandlerUsesLineFormatterWhichIgnoresEmptyArrays() { $record = array('message' => 'msg', 'context' => array(), 'level' => Logger::DEBUG, 'level_name' => Logger::getLevelName(Logger::DEBUG), 'channel' => 'channel', 'datetime' => new \DateTime(), 'extra' => array()); $expectedFormatter = new LineFormatter(null, null, true, true); $expected = $expectedFormatter->format($record); $handlerFormatter = $this->handler->getFormatter(); $actual = $handlerFormatter->format($record); $this->assertEquals($expected, $actual, 'Empty context and extra arrays should not be rendered'); }
/** * {@inheritdoc} */ public function format(array $record) { $vars = $this->normalizerFormatter->format($record); $output = $this->format; foreach ($vars['extra'] as $var => $val) { if (false !== strpos($output, '%extra.' . $var . '%')) { $output = str_replace('%extra.' . $var . '%', var_export($val, true), $output); unset($vars['extra'][$var]); } } foreach ($vars as $var => $val) { if (false !== strpos($output, '%' . $var . '%')) { $val_output = ''; if (is_array($val) && count($val) > 0 || is_array($val) === false) { $val_output = var_export($val, true); } $output = str_replace('%' . $var . '%', $val_output, $output); } } return $output; }
/** * Get the plain text message with LineFormatter's format method and add * metadata including the trace id then return the json string. * * @param array $record A record to format * @return mixed The formatted record */ public function format(array $record) { $message = parent::format($record); list($usec, $sec) = explode(" ", microtime()); $usec = (int) ((double) $usec * 1000000000); $sec = (int) $sec; $payload = ['message' => $message, 'timestamp' => ['seconds' => $sec, 'nanos' => $usec], 'thread' => '', 'severity' => $record['level_name']]; if (isset($_SERVER['HTTP_X_CLOUD_TRACE_CONTEXT'])) { $payload['traceId'] = explode("/", $_SERVER['HTTP_X_CLOUD_TRACE_CONTEXT'])[0]; } return "\n" . json_encode($payload); }
/** * Creates instance of Swift_Message to be sent * * @param string $content formatted email body to be sent * @param array $records Log records that formed the content * @return \Swift_Message */ protected function buildMessage($content, array $records) { $message = null; if ($this->messageTemplate instanceof \Swift_Message) { $message = clone $this->messageTemplate; $message->generateId(); } elseif (is_callable($this->messageTemplate)) { $message = call_user_func($this->messageTemplate, $content, $records); } if (!$message instanceof \Swift_Message) { throw new \InvalidArgumentException('Could not resolve message as instance of Swift_Message or a callable returning it'); } if ($records) { $subjectFormatter = new LineFormatter($message->getSubject()); $message->setSubject($subjectFormatter->format($this->getHighestRecord($records))); } $message->setBody($content); $message->setDate(time()); return $message; }
public function testDefFormatWithObject() { $formatter = new LineFormatter(null, 'Y-m-d'); $message = $formatter->format(array('level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), 'datetime' => new \DateTime(), 'extra' => array('foo' => new TestFoo(), 'bar' => new TestBar(), 'baz' => array(), 'res' => fopen('php://memory', 'rb')), 'message' => 'foobar')); if (version_compare(PHP_VERSION, '5.4.0', '>=')) { $this->assertEquals('[' . date('Y-m-d') . '] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}' . "\n", $message); } else { $this->assertEquals('[' . date('Y-m-d') . '] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\Formatter\\TestFoo: {"foo":"foo"})","bar":"[object] (Monolog\\Formatter\\TestBar: {})","baz":[],"res":"[resource]"}' . "\n", $message); } }
/** * {@inheritDoc} */ public function format(array $record) { $context = $record['context']; unset($record['context']); $output = parent::format($record); foreach ($context as $var => $val) { if (false !== strpos($output, '%context.' . $var . '%')) { $output = str_replace('%context.' . $var . '%', $this->convertToString($val), $output); unset($context[$var]); } else { $context[$var] = $this->convertToString($val); } } $output = str_replace('%context%', $this->convertToString($context), $output); return $output; }
/** * {@inheritdoc} */ public function format(array $record) { if ($record['level'] >= Logger::ERROR) { $record['start_tag'] = '<error>'; $record['end_tag'] = '</error>'; } elseif ($record['level'] >= Logger::NOTICE) { $record['start_tag'] = '<comment>'; $record['end_tag'] = '</comment>'; } elseif ($record['level'] >= Logger::INFO) { $record['start_tag'] = '<info>'; $record['end_tag'] = '</info>'; } else { $record['start_tag'] = '<debug>'; $record['end_tag'] = '</debug>'; } return parent::format($record); }
/** * {@inheritdoc} */ public function format(array $record) { // Drop the 'private' flag from the context unset($record['context']['private']); // Handle exceptions specially: pretty format and remove from context // Will be output for a '%exception%' placeholder in format $prettyException = ''; if (isset($record['context']['exception']) && strpos($this->format, '%exception%') !== false) { $e = $record['context']['exception']; unset($record['context']['exception']); if ($e instanceof Exception) { $prettyException = $this->normalizeException($e); } elseif (is_array($e)) { $prettyException = $this->normalizeExceptionArray($e); } else { $prettyException = $this->stringify($e); } } $output = parent::format($record); if (strpos($output, '%exception%') !== false) { $output = str_replace('%exception%', $prettyException, $output); } return $output; }
/** * {@inheritdoc} */ public function format(array $record) { $this->format = $this->getLevelFormat($record['level_name']); return parent::format($record); }
/** * Formats a log record. * * @param array $record A record to format * @return string The formatted record */ public function format(array $record) { $emoji = $this->getEmojiForLevel($record['level']); $output = parent::format($record); return $emoji . $output; }
/** * covers Bartlett\Monolog\Handler\GrowlHandler::handle * covers Bartlett\Monolog\Handler\GrowlHandler::pushProcessor * covers Bartlett\Monolog\Handler\GrowlHandler::setFormatter */ public function testHandleUsesProcessors() { $sender = 'PHP 7.0.0-dev'; $record = $this->getRecord(Logger::WARNING, 'caution message'); $record['extra']['sender'] = $sender; $formatter = new LineFormatter("%message%\n%level_name%\n%extra.sender%"); $this->growl->expects($this->any())->method('notify')->with($record['level_name'], $record['channel'], $formatter->format($record)); $handler = new GrowlHandler($this->growl); $handler->setFormatter($formatter); $handler->pushProcessor(function ($record) use($sender) { $record['extra']['sender'] = $sender; // 'PHP ' . phpversion(); return $record; }); $handler->handle($record); }
/** * {@inheritdoc} */ public function format(array $record) { $output = parent::format($record); return strip_tags($output); }
/** * {@inheritdoc} */ protected function send(string $content, array $records) { $contentType = $this->getContentType() ?: ($this->isHtmlBody($content) ? 'text/html' : 'text/plain'); if ($contentType !== 'text/html') { $content = wordwrap($content, $this->maxColumnWidth); } $headers = ltrim(implode("\r\n", $this->headers) . "\r\n", "\r\n"); $headers .= 'Content-type: ' . $contentType . '; charset=' . $this->getEncoding() . "\r\n"; if ($contentType === 'text/html' && false === strpos($headers, 'MIME-Version:')) { $headers .= 'MIME-Version: 1.0' . "\r\n"; } $subject = $this->subject; if ($records) { $subjectFormatter = new LineFormatter($this->subject); $subject = $subjectFormatter->format($this->getHighestRecord($records)); } $parameters = implode(' ', $this->parameters); foreach ($this->to as $to) { mail($to, $subject, $content, $headers, $parameters); } }
public function format(array $record) { $record = parent::format($record); return substr($record, 0, $this->outputLength); }