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

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