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

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