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