ErrorLog   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 61
c 0
b 0
f 0
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A write() 0 15 3
1
<?php
2
3
/**
4
 * This file is part of the Apix Project.
5
 *
6
 * (c) Franck Cassedanne <franck at ouarz.net>
7
 *
8
 * @license http://opensource.org/licenses/BSD-3-Clause  New BSD License
9
 */
10
11
namespace Apix\Log\Logger;
12
13
use Apix\Log\LogEntry;
14
15
/**
16
 * Minimalist logger implementing PSR-3 relying on PHP's error_log().
17
 *
18
 * @author Franck Cassedanne <franck at ouarz.net>
19
 */
20
class ErrorLog extends AbstractLogger implements LoggerInterface
21
{
22
    const PHP  = 0;
23
    const MAIL = 1;
24
    const FILE = 3;
25
    const SAPI = 4;
26
27
    /**
28
     * Holds the destination string (filename path or email address).
29
     * @var string
30
     */
31
    protected $destination;
32
33
    /**
34
     * Holds the message/delivery type:
35
     *      0: message is sent to PHP's system logger.
36
     *      1: message is sent by email to the address in the destination.
37
     *      3: message is appended to the file destination.
38
     *      4: message is sent directly to the SAPI.
39
     * @var integer
40
     */
41
    protected $type;
42
43
    /**
44
     * Holds a string of additional (mail) headers.
45
     * @var string|null
46
     * @see http://php.net/manual/en/function.mail.php
47
     */
48
    protected $headers = null;
49
50
    /**
51
     * Constructor.
52
     * @param string|null $file The filename to log messages to.
53
     * @param integer     $type The messag/delivery type.
54
     */
55 172
    public function __construct($file = null, $type = self::PHP)
56
    {
57 172
        $this->destination = $file;
58 172
        $this->type = $type;
59 43
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64 328
    public function write(LogEntry $log)
65
    {
66 328
        $message = (string) $log;
67
68 328
        if(!$this->deferred && $this->type == self::FILE) {
69 164
            $message .= $log->formatter->separator;
70 41
        }
71
72 328
        return error_log(
73 328
            $message,
74 328
            $this->type,
75 328
            $this->destination,
76 328
            $this->headers
77 82
        );
78
    }
79
80
}