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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations)
Fri Mar 28 06:44:20 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +12 -3 lines
VERBOSE mode

1 <?
2 /**
3 * This file contains the Class::Logger class.
4 *
5 * @author Andreas Motl <andreas.motl@ilo.de>
6 * @package org.netfrag.glib
7 * @name Class::Logger
8 *
9 */
10
11
12 /**
13 * <b>Cvs-Log:</b>
14 *
15 * <pre>
16 *
17 * $Id: Logger.php,v 1.10 2003/03/28 03:04:26 joko Exp $
18 *
19 * $Log: Logger.php,v $
20 * Revision 1.10 2003/03/28 03:04:26 joko
21 * enhanced conditions for debugging
22 *
23 * Revision 1.9 2003/03/27 15:59:55 joko
24 * enhanced 'function log'
25 *
26 * Revision 1.8 2003/03/11 02:23:02 joko
27 * + fixed metadata for phpDocumentor
28 *
29 * Revision 1.7 2003/03/11 02:14:23 joko
30 * + fixed metadata for phpDocumentor
31 *
32 * Revision 1.6 2003/03/11 02:04:36 joko
33 * + fixed metadata for phpDocumentor
34 *
35 * Revision 1.5 2003/03/11 01:42:59 joko
36 * + fixed metadata for phpDocumentor
37 *
38 * Revision 1.4 2003/03/11 01:22:24 joko
39 * + fixed metadata for phpDocumentor
40 *
41 * Revision 1.3 2003/03/11 01:12:53 joko
42 * + fixed metadata for phpDocumentor
43 *
44 * Revision 1.2 2003/03/05 18:54:43 joko
45 * updated docu - phpDocumentor is very strict about its 'blocks'...
46 *
47 * Revision 1.1 2003/03/03 21:26:43 joko
48 * refactored from DesignPattern::Logger
49 *
50 * Revision 1.4 2003/02/13 00:43:41 joko
51 * + logfile name now can get passed via defined constant
52 *
53 * Revision 1.3 2003/02/09 17:14:49 joko
54 * + now able to redirect errors raised by PEAR to logfile
55 *
56 * Revision 1.2 2003/02/03 14:47:49 joko
57 * + some code from DesignPattern::Bridge
58 *
59 * Revision 1.1 2003/02/03 03:33:48 joko
60 * + initial commit
61 *
62 * </pre>
63 *
64 */
65
66
67 /**
68 * This requires Class::Abstract as a base class
69 *
70 */
71 php::loadModule('Class::Abstract');
72
73
74 /**
75 * --- Class::Inner
76 *
77 * @author Andreas Motl <andreas.motl@ilo.de>
78 * @copyright (c) 2003 - All Rights reserved.
79 * @license GNU LGPL (GNU Lesser General Public License)
80 *
81 * @link http://www.netfrag.org/~joko/
82 * @link http://www.gnu.org/licenses/lgpl.txt
83 *
84 * @package org.netfrag.glib
85 * @subpackage Class
86 * @name Class::Logger
87 *
88 *
89 */
90 class Class_Logger extends Class_Abstract {
91
92 var $logger;
93 var $logfile;
94 var $enabled;
95
96 function Class_Logger() {
97 $this->constructor();
98 }
99
100 function constructor() {
101 // FIXME: this is hardcoded!
102 $logfile = 'logfile.txt';
103 if (defined('LOGFILE')) {
104 $logfile = LOGFILE;
105 }
106 $this->_init_logger($logfile, 1);
107 }
108
109
110 // TODO: split by loglevel here to make seperated logfiles possible (debug, normal, errors)
111 // TODO: optional: transmit logging messages via tcp - don't write them to disk (a handler for PEAR::Log)
112 function log($msg, $level = PEAR_LOG_DEBUG) {
113 //print "log: $msg<br>";
114 if ($this->logger) {
115 $this->logger->log($msg, $level);
116 } else {
117 // TODO: how are these type of errors handled?
118 //print "error-message: $msg<br>";
119 }
120
121 // TODO: modify this condition: make it more flexible: introduce '$this->ERRORS_STDOUT' or s.th.l.th.
122 //$debug_condition = $this->DEBUG || $level <= PEAR_LOG_WARNING;
123 $debug_condition = $this->DEBUG;
124 //$error_condition = $level <= PEAR_LOG_ERR;
125 $error_condition = $level <= PEAR_LOG_WARNING;
126
127 $label = 'Unknown'; $color = 'black';
128 if ($debug_condition) { $label = 'Debug'; $color = 'darkgreen'; }
129 if ($error_condition) { $label = 'Error'; $color = 'red'; }
130
131 $stdout_condition = constants::get('VERBOSE') && $level && ($debug_condition || $error_condition);
132 if ($stdout_condition) {
133 // TODO: what now?
134 //user_error($msg);
135 //print "<div><span style=\"color: $color;\"><b>$label</b></span>[$level]: <i>$msg</i></div>";
136 $style = html_style("text/css", '.boxlabel_red { color: red; font-weight:bold; }');
137 $box = html_span();
138 //$box->set_style("border-bottom: 1px solid black;");
139 $box->add( html_span('boxlabel_red', $label), "[$level]: $msg", html_br() );
140 print $style->render();
141 print $box->render();
142 }
143
144 }
145
146 function _init_logger($logfile, $enable = 0) {
147 $this->logfile = $logfile;
148 $this->enabled = $enable;
149 //print Dumper($this);
150 $this->_call_PEAR_Log_singleton();
151 $this->_pear_errors_redirect();
152 }
153
154 function _call_PEAR_Log_singleton() {
155
156 // $logfile = 'log.txt';
157 // $logfile = $this->config[path][base] . "core/var/log/logfile.txt";
158
159 // TODO: maybe include userid here?
160 //$log_ident = substr(session_id(), 10, 6);
161 $log_ident = session_id();
162 $outkey = 'dummy';
163 if ($this->enabled) {
164 $outkey = 'file';
165 }
166
167 if (class_exists('Log')) {
168 $this->logger = &Log::singleton($outkey, $this->logfile, $log_ident, array( timestampFormat => "%Y-%m-%d %H:%M:%S" ));
169 }
170 //$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG );
171
172 }
173
174 function _pear_errors_redirect() {
175 // 1. use PEAR::setErrorHandling
176 //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_function_handler");
177 // ... this doesn't work since the method thinks it's called oo-style,
178 // which is *not* the case here
179
180 // 2. use $GLOBALS to set global PEAR variables
181 $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
182 $GLOBALS['_PEAR_default_error_options'] = array($this, "_pear_error_receive");
183 }
184
185 function _pear_error_receive($errorObject) {
186 // trace
187 //print Dumper($errorObject);
188 $this->log( "PEAR_Error->message: " . $errorObject->message, PEAR_LOG_ERR);
189 }
190
191 }
192
193 ?>

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