/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/Logger.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/DesignPattern/Logger.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Sun Feb 9 17:14:49 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.2: +35 -10 lines
+ now able to redirect errors raised by PEAR to logfile

1 joko 1.1 <?
2     // ---------------------------------------------------------------------------
3 joko 1.3 // $Id: Logger.php,v 1.2 2003/02/03 14:47:49 joko Exp $
4 joko 1.1 // ---------------------------------------------------------------------------
5 joko 1.2 // $Log: Logger.php,v $
6 joko 1.3 // Revision 1.2 2003/02/03 14:47:49 joko
7     // + some code from DesignPattern::Bridge
8     //
9 joko 1.2 // Revision 1.1 2003/02/03 03:33:48 joko
10     // + initial commit
11     //
12 joko 1.1 // ---------------------------------------------------------------------------
13    
14    
15     class DesignPattern_Logger {
16    
17 joko 1.2 var $logger;
18     var $logfile;
19     var $enabled;
20    
21 joko 1.3 /*
22     function DesignPattern_Logger() {
23     $this->constructor();
24     }
25     */
26    
27 joko 1.2 function constructor() {
28     // FIXME: this is hardcoded!
29     $this->_init_logger("../core/var/log/logfile.txt", 1);
30     }
31    
32 joko 1.3 // TODO: split by loglevel here to make seperated logfiles possible (debug, normal, errors)
33     // TODO: optional: transmit logging messages via tcp - don't write them to disk (a handler for PEAR::Log)
34     function log($msg, $level = PEAR_LOG_DEBUG) {
35 joko 1.2 //print "log: $msg<br>";
36 joko 1.1 if ($this->logger) {
37     $this->logger->log($msg, $level);
38     } else {
39     // TODO: how are these type of errors handled?
40     //print "error-message: $msg<br>";
41     }
42     }
43 joko 1.2
44     function _init_logger($logfile, $enable = 0) {
45     $this->logfile = $logfile;
46     $this->enabled = $enable;
47     //print Dumper($this);
48 joko 1.3 $this->_call_PEAR_Log_singleton();
49     $this->_pear_errors_redirect();
50 joko 1.2 }
51    
52 joko 1.3 function _call_PEAR_Log_singleton() {
53    
54 joko 1.2 // $logfile = 'log.txt';
55     // $logfile = $this->config[path][base] . "core/var/log/logfile.txt";
56    
57     // TODO: maybe include userid here?
58     //$log_ident = substr(session_id(), 10, 6);
59     $log_ident = session_id();
60     $outkey = 'dummy';
61     if ($this->enabled) {
62     $outkey = 'file';
63     }
64 joko 1.3 $this->logger = &Log::singleton($outkey, $this->logfile, $log_ident, array( timestampFormat => "%Y-%m-%d %H:%M:%S" ));
65 joko 1.2 //$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG );
66 joko 1.3 }
67    
68     function _pear_errors_redirect() {
69     // 1. use PEAR::setErrorHandling
70     //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_function_handler");
71     // ... this doesn't work since the method thinks it's called oo-style,
72     // which is *not* the case here
73    
74     // 2. use $GLOBALS to set global PEAR variables
75     $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
76     $GLOBALS['_PEAR_default_error_options'] = array($this, "_pear_error_receive");
77     }
78    
79     function _pear_error_receive($errorObject) {
80     // trace
81     //print Dumper($errorObject);
82     $this->log( "PEAR_Error->message: " . $errorObject->message, PEAR_LOG_ERR);
83 joko 1.2 }
84    
85 joko 1.1 }
86    
87     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed