<?php

namespace KupShop\KupShopBundle\Util\Logging;

class LogstashFormatter extends \Monolog\Formatter\LogstashFormatter
{
    protected function formatV1(array $record)
    {
        if (empty($record['datetime'])) {
            $record['datetime'] = gmdate('c');
        }
        $message = [
            '@timestamp' => $record['datetime'],
            '@version' => 1,
            'host' => $this->systemName,
        ];
        if (isset($record['message'])) {
            $message['message'] = $record['message'];
        }
        if (isset($record['channel'])) {
            $message['type'] = $record['channel'];
            $message['channel'] = $record['channel'];
        }
        if (isset($record['level_name'])) {
            $message['level'] = $record['level_name'];
        }
        if ($this->applicationName) {
            $message['type'] = $this->applicationName;
        }
        if (!empty($record['extra'])) {
            $message[$this->extraPrefix] = $record['extra'];
        }
        if (!empty($record['context'])) {
            $message[$this->contextPrefix] = $record['context'];
        }

        global $cfg;
        $message['engine'] = $cfg['Program']['version']['folder'];
        $message['web'] = $cfg['Addr']['print'];

        return $message;
    }
}
