/[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.7 - (show annotations)
Tue Mar 11 02:14:23 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.6: +7 -1 lines
+ fixed metadata for phpDocumentor

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

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