| 3 | //  $Id$ | //  $Id$ | 
| 4 | // --------------------------------------------------------------------------- | // --------------------------------------------------------------------------- | 
| 5 | //  $Log$ | //  $Log$ | 
| 6 |  | //  Revision 1.4  2003/02/13 00:43:41  joko | 
| 7 |  | //  + logfile name now can get passed via defined constant | 
| 8 |  | // | 
| 9 |  | //  Revision 1.3  2003/02/09 17:14:49  joko | 
| 10 |  | //  + now able to redirect errors raised by PEAR to logfile | 
| 11 |  | // | 
| 12 | //  Revision 1.2  2003/02/03 14:47:49  joko | //  Revision 1.2  2003/02/03 14:47:49  joko | 
| 13 | //  + some code from DesignPattern::Bridge | //  + some code from DesignPattern::Bridge | 
| 14 | // | // | 
| 24 | var $logfile; | var $logfile; | 
| 25 | var $enabled; | var $enabled; | 
| 26 |  |  | 
| 27 |  | /* | 
| 28 |  | function DesignPattern_Logger() { | 
| 29 |  | $this->constructor(); | 
| 30 |  | } | 
| 31 |  | */ | 
| 32 |  |  | 
| 33 | function constructor() { | function constructor() { | 
| 34 | // FIXME: this is hardcoded! | // FIXME: this is hardcoded! | 
| 35 | $this->_init_logger("../core/var/log/logfile.txt", 1); | $logfile = 'logfile.txt'; | 
| 36 |  | if (defined('LOGFILE')) { | 
| 37 |  | $logfile = LOGFILE; | 
| 38 |  | } | 
| 39 |  | $this->_init_logger($logfile, 1); | 
| 40 | } | } | 
| 41 |  |  | 
| 42 | function log($msg, $level) { | // TODO: split by loglevel here to make seperated logfiles possible (debug, normal, errors) | 
| 43 |  | // TODO: optional: transmit logging messages via tcp - don't write them to disk (a handler for PEAR::Log) | 
| 44 |  | function log($msg, $level = PEAR_LOG_DEBUG) { | 
| 45 | //print "log: $msg<br>"; | //print "log: $msg<br>"; | 
| 46 | if ($this->logger) { | if ($this->logger) { | 
| 47 | $this->logger->log($msg, $level); | $this->logger->log($msg, $level); | 
| 55 | $this->logfile = $logfile; | $this->logfile = $logfile; | 
| 56 | $this->enabled = $enable; | $this->enabled = $enable; | 
| 57 | //print Dumper($this); | //print Dumper($this); | 
| 58 | $this->_init_Log_singleton(); | $this->_call_PEAR_Log_singleton(); | 
| 59 |  | $this->_pear_errors_redirect(); | 
| 60 | } | } | 
| 61 |  |  | 
| 62 | function _init_Log_singleton() { | function _call_PEAR_Log_singleton() { | 
| 63 | // 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. |  | 
| 64 | //      $logfile = 'log.txt'; | //      $logfile = 'log.txt'; | 
| 65 | //      $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; | //      $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; | 
| 66 |  |  | 
| 71 | if ($this->enabled) { | if ($this->enabled) { | 
| 72 | $outkey = 'file'; | $outkey = 'file'; | 
| 73 | } | } | 
| 74 | $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" )); | 
| 75 | //$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); | //$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); | 
| 76 | } | } | 
| 77 |  |  | 
| 78 |  | function _pear_errors_redirect() { | 
| 79 |  | // 1. use PEAR::setErrorHandling | 
| 80 |  | //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_function_handler"); | 
| 81 |  | // ... this doesn't work since the method thinks it's called oo-style, | 
| 82 |  | // which is *not* the case here | 
| 83 |  |  | 
| 84 |  | // 2. use $GLOBALS to set global PEAR variables | 
| 85 |  | $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK; | 
| 86 |  | $GLOBALS['_PEAR_default_error_options'] = array($this, "_pear_error_receive"); | 
| 87 |  | } | 
| 88 |  |  | 
| 89 |  | function _pear_error_receive($errorObject) { | 
| 90 |  | // trace | 
| 91 |  | //print Dumper($errorObject); | 
| 92 |  | $this->log( "PEAR_Error->message: " . $errorObject->message, PEAR_LOG_ERR); | 
| 93 |  | } | 
| 94 |  |  | 
| 95 | } | } | 
| 96 |  |  | 
| 97 | ?> | ?> |