/[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.6 - (hide annotations)
Tue Mar 11 02:04:36 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.5: +6 -5 lines
+ fixed metadata for phpDocumentor

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

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