annotate plugins/debug_logger/debug_logger.php @ 28:538b3d58eb89

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