Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
 
3
/*
4
 * This file is part of the Monolog package.
5
 *
6
 * (c) Jordi Boggiano <j.boggiano@seld.be>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Monolog\Formatter;
13
 
14
use DateTimeInterface;
15
use Monolog\LogRecord;
16
 
17
/**
18
 * Encodes message information into JSON in a format compatible with Cloud logging.
19
 *
621 lars 20
 * @see https://cloud.google.com/logging/docs/structured-logging
148 lars 21
 * @see https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
22
 *
23
 * @author Luís Cobucci <lcobucci@gmail.com>
24
 */
25
final class GoogleCloudLoggingFormatter extends JsonFormatter
26
{
27
    /** {@inheritdoc} **/
28
    public function format(array $record): string
29
    {
30
        // Re-key level for GCP logging
31
        $record['severity'] = $record['level_name'];
621 lars 32
        $record['time'] = $record['datetime']->format(DateTimeInterface::RFC3339_EXTENDED);
148 lars 33
 
34
        // Remove keys that are not used by GCP
35
        unset($record['level'], $record['level_name'], $record['datetime']);
36
 
37
        return parent::format($record);
38
    }
39
}
40