commit | author | age
|
cc97ea
|
1 |
<?php |
T |
2 |
|
|
3 |
/** |
|
4 |
* Debug Logger |
|
5 |
* |
|
6 |
* Enhanced logging for debugging purposes. It is not recommened |
|
7 |
* to be enabled on production systems without testing because of |
|
8 |
* the somewhat increased memory, cpu and disk i/o overhead. |
|
9 |
* |
|
10 |
* Debug Logger listens for existing console("message") calls and |
|
11 |
* introduces start and end tags as well as free form tagging |
|
12 |
* which can redirect messages to files. The resulting log files |
|
13 |
* provide timing and tag quantity results. |
|
14 |
* |
|
15 |
* Enable the plugin in config/main.inc.php and add your desired |
|
16 |
* log types and files. |
|
17 |
* |
|
18 |
* @version 1.0 |
|
19 |
* @author Ziba Scott |
|
20 |
* @website http://roundcube.net |
|
21 |
* |
|
22 |
* Example: |
|
23 |
* |
|
24 |
* config/main.inc.php: |
|
25 |
* |
|
26 |
* // $rcmail_config['debug_logger'][type of logging] = name of file in log_dir |
|
27 |
* // The 'master' log includes timing information |
|
28 |
* $rcmail_config['debug_logger']['master'] = 'master'; |
|
29 |
* // If you want sql messages to also go into a separate file |
|
30 |
* $rcmail_config['debug_logger']['sql'] = 'sql'; |
|
31 |
* |
|
32 |
* index.php (just after $RCMAIL->plugins->init()): |
|
33 |
* |
|
34 |
* console("my test","start"); |
|
35 |
* console("my message"); |
|
36 |
* console("my sql calls","start"); |
|
37 |
* console("cp -r * /dev/null","shell exec"); |
|
38 |
* console("select * from example","sql"); |
|
39 |
* console("select * from example","sql"); |
|
40 |
* console("select * from example","sql"); |
|
41 |
* console("end"); |
|
42 |
* console("end"); |
|
43 |
* |
|
44 |
* |
|
45 |
* logs/master (after reloading the main page): |
|
46 |
* |
|
47 |
* [17-Feb-2009 16:51:37 -0500] start: Task: mail. |
|
48 |
* [17-Feb-2009 16:51:37 -0500] start: my test |
|
49 |
* [17-Feb-2009 16:51:37 -0500] my message |
|
50 |
* [17-Feb-2009 16:51:37 -0500] shell exec: cp -r * /dev/null |
|
51 |
* [17-Feb-2009 16:51:37 -0500] start: my sql calls |
|
52 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
53 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
54 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
55 |
* [17-Feb-2009 16:51:37 -0500] end: my sql calls - 0.0018 seconds shell exec: 1, sql: 3, |
|
56 |
* [17-Feb-2009 16:51:37 -0500] end: my test - 0.0055 seconds shell exec: 1, sql: 3, |
|
57 |
* [17-Feb-2009 16:51:38 -0500] end: Task: mail. - 0.8854 seconds shell exec: 1, sql: 3, |
|
58 |
* |
|
59 |
* logs/sql (after reloading the main page): |
|
60 |
* |
|
61 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
62 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
63 |
* [17-Feb-2009 16:51:37 -0500] sql: select * from example |
|
64 |
*/ |
|
65 |
class debug_logger extends rcube_plugin |
|
66 |
{ |
|
67 |
function init() |
|
68 |
{ |
|
69 |
require_once(dirname(__FILE__).'/runlog/runlog.php'); |
|
70 |
$this->runlog = new runlog(); |
|
71 |
|
|
72 |
if(!rcmail::get_instance()->config->get('log_dir')){ |
|
73 |
rcmail::get_instance()->config->set('log_dir',INSTALL_PATH.'logs'); |
|
74 |
} |
|
75 |
|
|
76 |
$log_config = rcmail::get_instance()->config->get('debug_logger',array()); |
|
77 |
|
|
78 |
foreach($log_config as $type=>$file){ |
|
79 |
$this->runlog->set_file(rcmail::get_instance()->config->get('log_dir').'/'.$file, $type); |
|
80 |
} |
|
81 |
|
|
82 |
$start_string = ""; |
|
83 |
$action = rcmail::get_instance()->action; |
|
84 |
$task = rcmail::get_instance()->task; |
|
85 |
if($action){ |
|
86 |
$start_string .= "Action: ".$action.". "; |
|
87 |
} |
|
88 |
if($task){ |
|
89 |
$start_string .= "Task: ".$task.". "; |
|
90 |
} |
|
91 |
$this->runlog->start($start_string); |
|
92 |
|
|
93 |
$this->add_hook('console', array($this, 'console')); |
|
94 |
$this->add_hook('authenticate', array($this, 'authenticate')); |
|
95 |
} |
|
96 |
|
|
97 |
function authenticate($args){ |
|
98 |
$this->runlog->note('Authenticating '.$args['user'].'@'.$args['host']); |
|
99 |
return $args; |
|
100 |
} |
|
101 |
|
|
102 |
function console($args){ |
|
103 |
$note = $args[0]; |
|
104 |
$type = $args[1]; |
|
105 |
|
|
106 |
|
|
107 |
if(!isset($args[1])){ |
|
108 |
// This could be extended to detect types based on the |
|
109 |
// file which called console. For now only rcube_imap.inc is supported |
57307b
|
110 |
$bt = debug_backtrace(); |
cc97ea
|
111 |
$file = $bt[3]['file']; |
T |
112 |
switch(basename($file)){ |
|
113 |
case 'rcube_imap.php': |
|
114 |
$type = 'imap'; |
|
115 |
break; |
|
116 |
default: |
|
117 |
$type = FALSE; |
|
118 |
break; |
|
119 |
} |
|
120 |
} |
|
121 |
switch($note){ |
|
122 |
case 'end': |
|
123 |
$type = 'end'; |
|
124 |
break; |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
switch($type){ |
|
129 |
case 'start': |
|
130 |
$this->runlog->start($note); |
|
131 |
break; |
|
132 |
case 'end': |
|
133 |
$this->runlog->end(); |
|
134 |
break; |
|
135 |
default: |
|
136 |
$this->runlog->note($note, $type); |
|
137 |
break; |
|
138 |
} |
|
139 |
return $args; |
|
140 |
} |
|
141 |
|
|
142 |
function __destruct(){ |
|
143 |
$this->runlog->end(); |
|
144 |
} |
|
145 |
} |
|
146 |
?> |