Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Tsv
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 format
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <dev@noladev.com>
8 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Log\Formatter;
16
17use Pop\Log\Context;
18
19/**
20 * TSV line formatter
21 *
22 * @category   Pop
23 * @package    Pop\Log
24 * @author     Nick Sagona, III <dev@noladev.com>
25 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    5.0.0
28 */
29class Tsv implements FormatterInterface
30{
31
32    /**
33     * Format a single log entry into a TSV line
34     *
35     * @param  string $level
36     * @param  string $message
37     * @param  array  $context
38     * @return string
39     */
40    public function format(string $level, string $message, array $context): string
41    {
42        $message = '"' . str_replace('"', '\"', Context::sanitize($message)) . '"';
43        return Context::sanitize($context['timestamp']) . "\t" . $level . "\t" .
44            Context::sanitize($context['name']) . "\t" . $message . "\t" .
45            Context::sanitize(Context::serialize($context));
46    }
47
48}