Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | 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
 *
20
 * @see https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
21
 *
22
 * @author Luís Cobucci <lcobucci@gmail.com>
23
 */
24
final class GoogleCloudLoggingFormatter extends JsonFormatter
25
{
26
    /** {@inheritdoc} **/
27
    public function format(array $record): string
28
    {
29
        // Re-key level for GCP logging
30
        $record['severity'] = $record['level_name'];
31
        $record['timestamp'] = $record['datetime']->format(DateTimeInterface::RFC3339_EXTENDED);
32
 
33
        // Remove keys that are not used by GCP
34
        unset($record['level'], $record['level_name'], $record['datetime']);
35
 
36
        return parent::format($record);
37
    }
38
}
39