Display Log
@@ -0,0 +1,68 @@ | ||
1 | +<?php | |
2 | + | |
3 | +class Logger_Display extends Logger | |
4 | +{ | |
5 | + var $_logs = array(); | |
6 | + | |
7 | + function Logger_Display() | |
8 | + { | |
9 | + register_shutdown_function(array(&$this, '_display')); | |
10 | + } | |
11 | + | |
12 | + function fatal($message, $caller = null) | |
13 | + { | |
14 | + $this->_logging(LEVEL_FATAL, $message, $caller); | |
15 | + } | |
16 | + | |
17 | + function error($message, $caller = null) | |
18 | + { | |
19 | + $this->_logging(LEVEL_ERROR, $message, $caller); | |
20 | + } | |
21 | + | |
22 | + function warn($message, $caller = null) | |
23 | + { | |
24 | + $this->_logging(LEVEL_WARN, $message, $caller); | |
25 | + } | |
26 | + | |
27 | + function info($message, $caller = null) | |
28 | + { | |
29 | + $this->_logging(LEVEL_INFO, $message, $caller); | |
30 | + } | |
31 | + | |
32 | + function debug($message, $caller = null) | |
33 | + { | |
34 | + $this->_logging(LEVEL_DEBUG, $message, $caller); | |
35 | + } | |
36 | + | |
37 | + function trace($message, $caller = null) | |
38 | + { | |
39 | + $this->_logging(LEVEL_TRACE,$message, $caller); | |
40 | + } | |
41 | + | |
42 | + function _logging($logLevel, $message, $caller) | |
43 | + { | |
44 | + if ($logLevel < LOG_LEVEL) { | |
45 | + return; | |
46 | + } | |
47 | + $now = date("Y/m/d H:i:s"); | |
48 | + | |
49 | + $levels = array( | |
50 | + LEVEL_FATAL => 'fatal', | |
51 | + LEVEL_ERROR => 'error', | |
52 | + LEVEL_WARN => 'warn', | |
53 | + LEVEL_INFO => 'info', | |
54 | + LEVEL_DEBUG => 'debug', | |
55 | + LEVEL_TRACE => 'trace', | |
56 | + ); | |
57 | + | |
58 | + $this->_logs[] = sprintf("[%s] [%s] %s - %s\n", $now, $levels[$logLevel], $message, $caller); | |
59 | + } | |
60 | + | |
61 | + function _display() | |
62 | + { | |
63 | + foreach ($this->_logs as $log) { | |
64 | + print htmlspecialchars($log, ENT_QUOTES).'<br/>'; | |
65 | + } | |
66 | + } | |
67 | +} | |
68 | +?> |