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

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