4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Formatter;
15 * Encodes message information into JSON in a format compatible with Loggly.
17 * @author Adam Pancutt <adam@pancutt.com>
19 class LogglyFormatter extends JsonFormatter
22 * Overrides the default batch mode to new lines for compatibility with the
25 * @param int $batchMode
27 public function __construct($batchMode = self::BATCH_MODE_NEWLINES, $appendNewline = false)
29 parent::__construct($batchMode, $appendNewline);
33 * Appends the 'timestamp' parameter for indexing by Loggly.
35 * @see https://www.loggly.com/docs/automated-parsing/#json
36 * @see \Monolog\Formatter\JsonFormatter::format()
38 public function format(array $record)
40 if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTime)) {
41 $record["timestamp"] = $record["datetime"]->format("Y-m-d\TH:i:s.uO");
42 // TODO 2.0 unset the 'datetime' parameter, retained for BC
45 return parent::format($record);