1 |
<?php |
2 |
// $Id: console.php,v 1.7 2002/12/02 05:23:00 jon Exp $ |
3 |
|
4 |
/** |
5 |
* The Log_console class is a concrete implementation of the Log:: |
6 |
* abstract class which writes message to the text console. |
7 |
* |
8 |
* @author Jon Parise <jon@php.net> |
9 |
* @version $Revision: 1.7 $ |
10 |
* @package Log |
11 |
*/ |
12 |
class Log_console extends Log |
13 |
{ |
14 |
/** |
15 |
* Constructs a new Log_console object. |
16 |
* |
17 |
* @param string $name Ignored. |
18 |
* @param string $ident The identity string. |
19 |
* @param array $conf The configuration array. |
20 |
* @param array $maxLevel Maximum priority level at which to log. |
21 |
* @access public |
22 |
*/ |
23 |
function Log_console($name, $ident = '', $conf = array(), |
24 |
$maxLevel = PEAR_LOG_DEBUG) |
25 |
{ |
26 |
$this->_ident = $ident; |
27 |
$this->_maxLevel = $maxLevel; |
28 |
} |
29 |
|
30 |
/** |
31 |
* Writes $message to the text console. Also, passes the message |
32 |
* along to any Log_observer instances that are observing this Log. |
33 |
* |
34 |
* @param string $message The textual message to be logged. |
35 |
* @param string $priority The priority of the message. Valid |
36 |
* values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, |
37 |
* PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, |
38 |
* PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. |
39 |
* The default is PEAR_LOG_INFO. |
40 |
* @return boolean True on success or false on failure. |
41 |
* @access public |
42 |
*/ |
43 |
function log($message, $priority = PEAR_LOG_INFO) |
44 |
{ |
45 |
/* Abort early if the priority is above the maximum logging level. */ |
46 |
if ($priority > $this->_maxLevel) { |
47 |
return false; |
48 |
} |
49 |
|
50 |
printf("%s %s [%s] %s\n", strftime('%b %d %H:%M:%S'), $this->_ident, |
51 |
Log::priorityToString($priority), $message); |
52 |
|
53 |
$this->notifyAll(array('priority' => $priority, 'message' => $message)); |
54 |
|
55 |
return true; |
56 |
} |
57 |
} |
58 |
|
59 |
?> |