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.
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.
15 * Enable the plugin in config/main.inc.php and add your desired
16 * log types and files.
20 * @website http://roundcube.net
24 * config/main.inc.php:
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';
32 * index.php (just after $RCMAIL->plugins->init()):
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");
45 * logs/master (after reloading the main page):
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,
59 * logs/sql (after reloading the main page):
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
65 class debug_logger extends rcube_plugin
69 require_once(dirname(__FILE__).'/runlog/runlog.php');
70 $this->runlog = new runlog();
72 if(!rcmail::get_instance()->config->get('log_dir')){
73 rcmail::get_instance()->config->set('log_dir',INSTALL_PATH.'logs');
76 $log_config = rcmail::get_instance()->config->get('debug_logger',array());
78 foreach($log_config as $type=>$file){
79 $this->runlog->set_file(rcmail::get_instance()->config->get('log_dir').'/'.$file, $type);
83 $action = rcmail::get_instance()->action;
84 $task = rcmail::get_instance()->task;
86 $start_string .= "Action: ".$action.". ";
89 $start_string .= "Task: ".$task.". ";
91 $this->runlog->start($start_string);
93 $this->add_hook('console', array($this, 'console'));
94 $this->add_hook('authenticate', array($this, 'authenticate'));
97 function authenticate($args){
98 $this->runlog->note('Authenticating '.$args['user'].'@'.$args['host']);
102 function console($args){
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
110 $bt = debug_backtrace();
111 $file = $bt[3]['file'];
112 switch(basename($file)){
113 case 'rcube_imap.php':
130 $this->runlog->start($note);
133 $this->runlog->end();
136 $this->runlog->note($note, $type);
142 function __destruct(){
143 $this->runlog->end();