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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Mar 5 18:54:43 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.1: +34 -1 lines
updated docu - phpDocumentor is very strict about its 'blocks'...

1 joko 1.1 <?
2 joko 1.2 /**
3     * This file contains the Class::Logger class.
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6     * @name Class::Logger
7     *
8     */
9    
10    
11 joko 1.1 // ---------------------------------------------------------------------------
12 joko 1.2 // $Id: Logger.php,v 1.1 2003/03/03 21:26:43 joko Exp $
13 joko 1.1 // ---------------------------------------------------------------------------
14     // $Log: Logger.php,v $
15 joko 1.2 // Revision 1.1 2003/03/03 21:26:43 joko
16     // refactored from DesignPattern::Logger
17     //
18 joko 1.1 // Revision 1.4 2003/02/13 00:43:41 joko
19     // + logfile name now can get passed via defined constant
20     //
21     // Revision 1.3 2003/02/09 17:14:49 joko
22     // + now able to redirect errors raised by PEAR to logfile
23     //
24     // Revision 1.2 2003/02/03 14:47:49 joko
25     // + some code from DesignPattern::Bridge
26     //
27     // Revision 1.1 2003/02/03 03:33:48 joko
28     // + initial commit
29     //
30     // ---------------------------------------------------------------------------
31    
32    
33    
34 joko 1.2 /**
35     * This requires Class::Abstract as a base class
36     *
37     */
38 joko 1.1 php::loadModule('Class::Abstract');
39 joko 1.2
40    
41     /**
42     * Class::Inner
43     *
44     * @author Andreas Motl <andreas.motl@ilo.de>
45     * @copyright (c) 2003 - All Rights reserved.
46     * @license GNU LGPL (GNU Lesser General Public License)
47     *
48     * @link http://www.netfrag.org/~joko/
49     * @link http://www.gnu.org/licenses/lgpl.txt
50     *
51     * @package org.netfrag.glib
52     * @subpackage Class
53     * @name Class::Logger
54     *
55     */
56 joko 1.1 class Class_Logger extends Class_Abstract {
57    
58     var $logger;
59     var $logfile;
60     var $enabled;
61    
62     function Class_Logger() {
63     $this->constructor();
64     }
65    
66     function constructor() {
67     // FIXME: this is hardcoded!
68     $logfile = 'logfile.txt';
69     if (defined('LOGFILE')) {
70     $logfile = LOGFILE;
71     }
72     $this->_init_logger($logfile, 1);
73     }
74    
75     // TODO: split by loglevel here to make seperated logfiles possible (debug, normal, errors)
76     // TODO: optional: transmit logging messages via tcp - don't write them to disk (a handler for PEAR::Log)
77     function log($msg, $level = PEAR_LOG_DEBUG) {
78     //print "log: $msg<br>";
79     if ($this->logger) {
80     $this->logger->log($msg, $level);
81     } else {
82     // TODO: how are these type of errors handled?
83     //print "error-message: $msg<br>";
84     }
85     }
86    
87     function _init_logger($logfile, $enable = 0) {
88     $this->logfile = $logfile;
89     $this->enabled = $enable;
90     //print Dumper($this);
91     $this->_call_PEAR_Log_singleton();
92     $this->_pear_errors_redirect();
93     }
94    
95     function _call_PEAR_Log_singleton() {
96    
97     // $logfile = 'log.txt';
98     // $logfile = $this->config[path][base] . "core/var/log/logfile.txt";
99    
100     // TODO: maybe include userid here?
101     //$log_ident = substr(session_id(), 10, 6);
102     $log_ident = session_id();
103     $outkey = 'dummy';
104     if ($this->enabled) {
105     $outkey = 'file';
106     }
107    
108     if (class_exists('Log')) {
109     $this->logger = &Log::singleton($outkey, $this->logfile, $log_ident, array( timestampFormat => "%Y-%m-%d %H:%M:%S" ));
110     }
111     //$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG );
112    
113     }
114    
115     function _pear_errors_redirect() {
116     // 1. use PEAR::setErrorHandling
117     //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_function_handler");
118     // ... this doesn't work since the method thinks it's called oo-style,
119     // which is *not* the case here
120    
121     // 2. use $GLOBALS to set global PEAR variables
122     $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
123     $GLOBALS['_PEAR_default_error_options'] = array($this, "_pear_error_receive");
124     }
125    
126     function _pear_error_receive($errorObject) {
127     // trace
128     //print Dumper($errorObject);
129     $this->log( "PEAR_Error->message: " . $errorObject->message, PEAR_LOG_ERR);
130     }
131    
132     }
133    
134     ?>

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