1 |
<?php |
2 |
// $Horde: horde/lib/Log/syslog.php,v 1.6 2000/06/28 21:36:13 jon Exp $ |
3 |
|
4 |
/** |
5 |
* The Log_syslog class is a concrete implementation of the Log:: |
6 |
* abstract class which sends messages to syslog on UNIX-like machines |
7 |
* (PHP emulates this with the Event Log on Windows machines). |
8 |
* |
9 |
* @author Chuck Hagenbuch <chuck@horde.org> |
10 |
* @version $Revision: 1.1 $ |
11 |
* @since Horde 1.3 |
12 |
*/ |
13 |
class Log_syslog extends Log { |
14 |
|
15 |
// {{{ properties |
16 |
|
17 |
/** Integer holding the log facility to use. */ |
18 |
var $name = LOG_SYSLOG; |
19 |
|
20 |
// }}} |
21 |
|
22 |
|
23 |
// {{{ constructor |
24 |
/** |
25 |
* Constructs a new syslog object. |
26 |
* |
27 |
* @param $log_name (optional) The syslog facility. |
28 |
* @param $ident (optional) The identity string. |
29 |
* @param $conf (optional) The configuration array. |
30 |
*/ |
31 |
function Log_syslog ($log_name = LOG_SYSLOG, $ident = '', $conf = false) { |
32 |
$this->name = $log_name; |
33 |
$this->ident = $ident; |
34 |
} |
35 |
// }}} |
36 |
|
37 |
|
38 |
// {{{ open() |
39 |
/** |
40 |
* Opens a connection to the system logger, if it has not already |
41 |
* been opened. This is implicitly called by log(), if necessary. |
42 |
*/ |
43 |
function open () { |
44 |
if (!$this->opened) { |
45 |
openlog($this->ident, LOG_PID, $this->name); |
46 |
$this->opened = true; |
47 |
} |
48 |
} |
49 |
// }}} |
50 |
|
51 |
// {{{ close() |
52 |
/** |
53 |
* Closes the connection to the system logger, if it is open. |
54 |
*/ |
55 |
function close () { |
56 |
if ($this->opened) { |
57 |
closelog(); |
58 |
$this->opened = false; |
59 |
} |
60 |
} |
61 |
// }}} |
62 |
|
63 |
// {{{ log() |
64 |
/** |
65 |
* Sends $message to the currently open syslog * connection. Calls |
66 |
* open() if necessary. Also passes the message along to any Log_observer |
67 |
* instances that are observing this Log. |
68 |
* |
69 |
* @param $message The textual message to be logged. |
70 |
* @param $priority (optional) The priority of the message. Valid |
71 |
* values are: LOG_EMERG, LOG_ALERT, LOG_CRIT, |
72 |
* LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, |
73 |
* and LOG_DEBUG. The default is LOG_INFO. |
74 |
*/ |
75 |
function log ($message, $priority = LOG_INFO) { |
76 |
if (!$this->opened) |
77 |
$this->open(); |
78 |
|
79 |
syslog($priority, $message); |
80 |
$this->notifyAll(array('priority' => $priority, 'message' => $message)); |
81 |
} |
82 |
// }}} |
83 |
|
84 |
} |
85 |
|
86 |
?> |