/[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.9 - (show annotations)
Thu Mar 27 15:59:55 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.8: +12 -1 lines
enhanced 'function log'

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

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