3 |
// $Id$ |
// $Id$ |
4 |
// --------------------------------------------------------------------------- |
// --------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.3 2003/02/09 17:14:49 joko |
7 |
|
// + now able to redirect errors raised by PEAR to logfile |
8 |
|
// |
9 |
// Revision 1.2 2003/02/03 14:47:49 joko |
// Revision 1.2 2003/02/03 14:47:49 joko |
10 |
// + some code from DesignPattern::Bridge |
// + some code from DesignPattern::Bridge |
11 |
// |
// |
21 |
var $logfile; |
var $logfile; |
22 |
var $enabled; |
var $enabled; |
23 |
|
|
24 |
|
/* |
25 |
|
function DesignPattern_Logger() { |
26 |
|
$this->constructor(); |
27 |
|
} |
28 |
|
*/ |
29 |
|
|
30 |
function constructor() { |
function constructor() { |
31 |
// FIXME: this is hardcoded! |
// FIXME: this is hardcoded! |
32 |
$this->_init_logger("../core/var/log/logfile.txt", 1); |
$this->_init_logger("../core/var/log/logfile.txt", 1); |
33 |
} |
} |
34 |
|
|
35 |
function log($msg, $level) { |
// TODO: split by loglevel here to make seperated logfiles possible (debug, normal, errors) |
36 |
|
// TODO: optional: transmit logging messages via tcp - don't write them to disk (a handler for PEAR::Log) |
37 |
|
function log($msg, $level = PEAR_LOG_DEBUG) { |
38 |
//print "log: $msg<br>"; |
//print "log: $msg<br>"; |
39 |
if ($this->logger) { |
if ($this->logger) { |
40 |
$this->logger->log($msg, $level); |
$this->logger->log($msg, $level); |
48 |
$this->logfile = $logfile; |
$this->logfile = $logfile; |
49 |
$this->enabled = $enable; |
$this->enabled = $enable; |
50 |
//print Dumper($this); |
//print Dumper($this); |
51 |
$this->_init_Log_singleton(); |
$this->_call_PEAR_Log_singleton(); |
52 |
|
$this->_pear_errors_redirect(); |
53 |
} |
} |
54 |
|
|
55 |
function _init_Log_singleton() { |
function _call_PEAR_Log_singleton() { |
56 |
// Log |
|
|
// valid logging-levels are: |
|
|
// LOG_EMERG, LOG_ALERT, LOG_CRIT, |
|
|
// LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. |
|
|
// The default is LOG_INFO. |
|
57 |
// $logfile = 'log.txt'; |
// $logfile = 'log.txt'; |
58 |
// $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; |
// $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; |
59 |
|
|
64 |
if ($this->enabled) { |
if ($this->enabled) { |
65 |
$outkey = 'file'; |
$outkey = 'file'; |
66 |
} |
} |
67 |
$this->logger = &Log::singleton($outkey, $this->logfile, $log_ident); |
$this->logger = &Log::singleton($outkey, $this->logfile, $log_ident, array( timestampFormat => "%Y-%m-%d %H:%M:%S" )); |
68 |
//$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); |
//$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); |
69 |
} |
} |
70 |
|
|
71 |
|
function _pear_errors_redirect() { |
72 |
|
// 1. use PEAR::setErrorHandling |
73 |
|
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_function_handler"); |
74 |
|
// ... this doesn't work since the method thinks it's called oo-style, |
75 |
|
// which is *not* the case here |
76 |
|
|
77 |
|
// 2. use $GLOBALS to set global PEAR variables |
78 |
|
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK; |
79 |
|
$GLOBALS['_PEAR_default_error_options'] = array($this, "_pear_error_receive"); |
80 |
|
} |
81 |
|
|
82 |
|
function _pear_error_receive($errorObject) { |
83 |
|
// trace |
84 |
|
//print Dumper($errorObject); |
85 |
|
$this->log( "PEAR_Error->message: " . $errorObject->message, PEAR_LOG_ERR); |
86 |
|
} |
87 |
|
|
88 |
} |
} |
89 |
|
|
90 |
?> |
?> |