1 |
joko |
1.2 |
<?php |
2 |
|
|
// $Id: observer.php,v 1.3 2002/10/22 00:13:47 jon Exp $ |
3 |
|
|
// $Horde: horde/lib/Log/observer.php,v 1.5 2000/06/28 21:36:13 jon Exp $ |
4 |
|
|
|
5 |
|
|
/** |
6 |
|
|
* The Log_observer:: class implements the Observer end of a |
7 |
|
|
* Subject-Observer pattern for watching log activity and taking |
8 |
|
|
* actions on exceptional events. |
9 |
|
|
* |
10 |
|
|
* @author Chuck Hagenbuch <chuck@horde.org> |
11 |
|
|
* @version $Revision: 1.3 $ |
12 |
|
|
* @since Horde 1.3 |
13 |
|
|
* @package Log |
14 |
|
|
*/ |
15 |
|
|
class Log_observer { |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* The minimum priority level of message that we want to hear |
19 |
|
|
* about. PEAR_LOG_EMERG is the highest priority, so we will only |
20 |
|
|
* hear messages with an integer priority value less than or |
21 |
|
|
* equal to ours. It defaults to PEAR_LOG_INFO, which listens to |
22 |
|
|
* everything except PEAR_LOG_DEBUG. |
23 |
|
|
* @var string |
24 |
|
|
*/ |
25 |
|
|
var $_priority = PEAR_LOG_INFO; |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* Basic Log_observer instance that just prints out messages |
30 |
|
|
* received. |
31 |
|
|
* @param string $priority priority level of message |
32 |
|
|
* @access public |
33 |
|
|
*/ |
34 |
|
|
function Log_observer($priority = PEAR_LOG_INFO) |
35 |
|
|
{ |
36 |
|
|
$this->_priority = $priority; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
/** |
40 |
|
|
* Attempts to return a concrete Log_observer instance of the |
41 |
|
|
* specified type. |
42 |
|
|
* |
43 |
|
|
* @param string $observer_type The type of concrate Log_observer subclass |
44 |
|
|
* to return. We will attempt to dynamically |
45 |
|
|
* include the code for this subclass. |
46 |
|
|
* @param string $priority priority level of message |
47 |
|
|
* @return object Log_observer The newly created concrete Log_observer |
48 |
|
|
* instance, or an false on an error. |
49 |
|
|
*/ |
50 |
|
|
function factory($observer_type, $priority = PEAR_LOG_INFO) |
51 |
|
|
{ |
52 |
|
|
$classfile = substr(__FILE__, 0, -(strlen(basename(__FILE__)))) . 'Log/' . $observer_type . '.php'; |
53 |
|
|
if (file_exists($classfile)) { |
54 |
|
|
include_once $classfile; |
55 |
|
|
$class = 'Log_' . $observer_type; |
56 |
|
|
return new $observer_type($priority); |
57 |
|
|
} else { |
58 |
|
|
return false; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* This is a stub method to make sure that LogObserver classes do |
64 |
|
|
* something when they are notified of a message. The default |
65 |
|
|
* behavior is to just print the message, which is obviously not |
66 |
|
|
* desireable in practically any situation - which is why you need |
67 |
|
|
* to override this method. :) |
68 |
|
|
* |
69 |
|
|
* @param array $messageOb A hash containing all information - the text |
70 |
|
|
* message itself, the priority, what log it came |
71 |
|
|
* from, etc. |
72 |
|
|
*/ |
73 |
|
|
function notify($messageOb) |
74 |
|
|
{ |
75 |
|
|
print_r($messageOb); |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
?> |