-
Notifications
You must be signed in to change notification settings - Fork 238
/
Syslog.php
62 lines (55 loc) · 1.4 KB
/
Syslog.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
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2009, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
namespace lithium\util\audit\logger\adapters;
/**
* The Syslog adapter facilitates logging messages to a syslogd backend.
*/
class Syslog extends \lithium\core\Object {
/**
* The last connection to have opened syslog. This will determine whether or
* not the log needs to be closed and reopened.
*
* @var string
*/
protected static $_lastOpenedBy;
/**
* Class constructor
*
* @return void
*/
public function __construct($config = array()) {
$defaults = array(
'identity' => false,
'options' => LOG_ODELAY,
'facility' => LOG_USER,
'priority' => LOG_INFO
);
parent::__construct($config + $defaults);
}
/**
* Appends `$data` to file `$type`.
*
* @param string $type
* @param string $message
* @return boolean True on successful write, false otherwise
*/
public function write($type, $message) {
if (static::$_lastOpenedBy != $type) {
closelog();
openlog(
$this->_config['identity'], $this->_config['options'], $this->_config['facility']
);
static::$_lastOpenedBy = $type;
}
$priority = $this->_config['priority'];
return function($self, $params, $chain) use ($priority) {
return syslog($priority, $params['message']);
};
}
}
?>