Log::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoConfigLib\Feature;
12
13
use WebinoConfigLib\Log\Writer;
14
15
/**
16
 * Class Log
17
 */
18
class Log extends AbstractLog
19
{
20
    /**
21
     * Default log file path
22
     */
23
    const DEFAULT_FILE_PATH = 'data/log/app.log';
24
25
    /**
26
     * @var bool
27
     */
28
    private static $useLastFilePath = false;
29
30
    /**
31
     * @param string $filePath
32
     */
33
    public function __construct($filePath = null)
34
    {
35
        parent::__construct();
36
37
        if (null === $filePath && !$this::$useLastFilePath) {
38
            $filePath = $this::DEFAULT_FILE_PATH;
39
        } else {
40
            $this::$useLastFilePath = true;
41
        }
42
43
        $this->writer = new Writer\Stream($filePath);
44
        $this->setWriterKey(basename($filePath));
45
        $this->setSimpleFormat();
46
    }
47
48
    /**
49
     * @param string $name
50
     * @return $this
51
     */
52
    public function setName($name)
53
    {
54
        $this->setWriterKey($name);
55
        return $this;
56
    }
57
58
    /**
59
     * Set simple message format
60
     *
61
     * @param string|null $format %timestamp% %priorityName% (%priority%): %message% %extra%
62
     * @return $this
63
     */
64
    public function setSimpleFormat($format = null)
65
    {
66
        $options = ['format' => $format ? $format : '%timestamp% %priorityName% (%priority%): %message%'];
67
        $this->writer->setFormatter('simple', $options);
68
        return $this;
69
    }
70
71
    /**
72
     * Set XML message format
73
     *
74
     * @return $this
75
     */
76
    public function setXmlFormat()
77
    {
78
        $this->writer->setFormatter('xml');
79
        return $this;
80
    }
81
}
82