/[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.4 - (hide annotations)
Thu Feb 13 00:43:41 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.3: +9 -2 lines
+ logfile name now can get passed via defined constant

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

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