Completed
Push — master ( 9b3fe3...b82616 )
by Hong
06:10 queued 03:55
created

DefaultFormatter::getEol()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Logger
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Logger\Formatter;
13
14
use Phoole\Logger\Entry\LogEntryInterface;
15
16
/**
17
 * DefaultFormatter
18
 *
19
 * @package Phoole\Logger
20
 */
21
class DefaultFormatter implements FormatterInterface
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function format(LogEntryInterface $entry): string
27
    {
28
        $context = $entry->getContext();
29
30
        $mesg = '';
31
        if (isset($context['__channel'])) {
32
            $mesg .= '[' . strtoupper($context['__channel']) . '] ';
33
        }
34
        $mesg .= $entry . $this->getEol();
35
36
        return  $mesg;
37
    }
38
   
39
    /**
40
     * Get EOL char base on the platform WIN or UNIX
41
     *
42
     * @return string
43
     */
44
    protected function getEol(): string
45
    {
46
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
47
            return "\r\n";
48
        } else {
49
            return "\n";
50
        }
51
    }
52
}
53