summaryrefslogtreecommitdiff
path: root/plugins/debug_logger/debug_logger.php
diff options
context:
space:
mode:
authorHugues Hiegel <root@paranoid>2015-04-21 12:49:44 +0200
committerHugues Hiegel <root@paranoid>2015-04-21 12:49:44 +0200
commit733f8e8d0ce6217d906d06dc4fb08e36d48ed794 (patch)
treecff28366ff63ea6596f8026e1698090bd0b9405c /plugins/debug_logger/debug_logger.php
parentef2e7b3f9d264ec146d4dae257b1e295ab3b462a (diff)
parenta4ba3df54834ee90fb2c9930669f1229dc80261a (diff)
Merge remote-tracking branch 'origin/master'HEADmaster
Conflicts: composer.json-dist config/defaults.inc.php plugins plugins/acl/acl.js plugins/acl/acl.php plugins/acl/skins/classic/templates/table.html plugins/acl/skins/larry/templates/table.html plugins/enigma/README plugins/enigma/config.inc.php.dist plugins/enigma/enigma.js plugins/enigma/enigma.php plugins/enigma/lib/enigma_driver.php plugins/enigma/lib/enigma_driver_gnupg.php plugins/enigma/lib/enigma_driver_phpssl.php plugins/enigma/lib/enigma_engine.php plugins/enigma/lib/enigma_error.php plugins/enigma/lib/enigma_key.php plugins/enigma/lib/enigma_signature.php plugins/enigma/lib/enigma_subkey.php plugins/enigma/lib/enigma_ui.php plugins/enigma/lib/enigma_userid.php plugins/enigma/localization/en_US.inc plugins/enigma/localization/ja_JP.inc plugins/enigma/localization/ru_RU.inc plugins/enigma/skins/classic/enigma.css plugins/enigma/skins/classic/templates/keys.html plugins/help/config.inc.php.dist plugins/help/help.php plugins/help/localization/en_US.inc plugins/jqueryui/jqueryui.php plugins/managesieve/Changelog plugins/managesieve/composer.json plugins/managesieve/config.inc.php.dist plugins/managesieve/lib/Roundcube/rcube_sieve.php plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php plugins/managesieve/localization/en_US.inc plugins/managesieve/managesieve.js plugins/managesieve/skins/classic/managesieve.css plugins/managesieve/skins/larry/managesieve.css plugins/password/README plugins/password/config.inc.php.dist plugins/password/drivers/ldap.php plugins/password/drivers/poppassd.php plugins/password/drivers/vpopmaild.php plugins/vcard_attachments/vcardattach.js plugins/zipdownload/zipdownload.php
Diffstat (limited to 'plugins/debug_logger/debug_logger.php')
-rw-r--r--plugins/debug_logger/debug_logger.php150
1 files changed, 150 insertions, 0 deletions
diff --git a/plugins/debug_logger/debug_logger.php b/plugins/debug_logger/debug_logger.php
new file mode 100644
index 000000000..07190e5a1
--- /dev/null
+++ b/plugins/debug_logger/debug_logger.php
@@ -0,0 +1,150 @@
+<?php
+
+/**
+ * Debug Logger
+ *
+ * Enhanced logging for debugging purposes. It is not recommened
+ * to be enabled on production systems without testing because of
+ * the somewhat increased memory, cpu and disk i/o overhead.
+ *
+ * Debug Logger listens for existing console("message") calls and
+ * introduces start and end tags as well as free form tagging
+ * which can redirect messages to files. The resulting log files
+ * provide timing and tag quantity results.
+ *
+ * Enable the plugin in config.inc.php and add your desired
+ * log types and files.
+ *
+ * @version @package_version@
+ * @author Ziba Scott
+ * @website http://roundcube.net
+ *
+ * Example:
+ *
+ * config.inc.php:
+ *
+ * // $config['debug_logger'][type of logging] = name of file in log_dir
+ * // The 'master' log includes timing information
+ * $config['debug_logger']['master'] = 'master';
+ * // If you want sql messages to also go into a separate file
+ * $config['debug_logger']['sql'] = 'sql';
+ *
+ * index.php (just after $RCMAIL->plugins->init()):
+ *
+ * console("my test","start");
+ * console("my message");
+ * console("my sql calls","start");
+ * console("cp -r * /dev/null","shell exec");
+ * console("select * from example","sql");
+ * console("select * from example","sql");
+ * console("select * from example","sql");
+ * console("end");
+ * console("end");
+ *
+ *
+ * logs/master (after reloading the main page):
+ *
+ * [17-Feb-2009 16:51:37 -0500] start: Task: mail.
+ * [17-Feb-2009 16:51:37 -0500] start: my test
+ * [17-Feb-2009 16:51:37 -0500] my message
+ * [17-Feb-2009 16:51:37 -0500] shell exec: cp -r * /dev/null
+ * [17-Feb-2009 16:51:37 -0500] start: my sql calls
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ * [17-Feb-2009 16:51:37 -0500] end: my sql calls - 0.0018 seconds shell exec: 1, sql: 3,
+ * [17-Feb-2009 16:51:37 -0500] end: my test - 0.0055 seconds shell exec: 1, sql: 3,
+ * [17-Feb-2009 16:51:38 -0500] end: Task: mail. - 0.8854 seconds shell exec: 1, sql: 3,
+ *
+ * logs/sql (after reloading the main page):
+ *
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ * [17-Feb-2009 16:51:37 -0500] sql: select * from example
+ */
+class debug_logger extends rcube_plugin
+{
+ function init()
+ {
+ require_once(__DIR__ . '/runlog/runlog.php');
+ $this->runlog = new runlog();
+
+ if(!rcmail::get_instance()->config->get('log_dir')){
+ rcmail::get_instance()->config->set('log_dir',INSTALL_PATH.'logs');
+ }
+
+ $log_config = rcmail::get_instance()->config->get('debug_logger',array());
+
+ foreach($log_config as $type=>$file){
+ $this->runlog->set_file(rcmail::get_instance()->config->get('log_dir').'/'.$file, $type);
+ }
+
+ $start_string = "";
+ $action = rcmail::get_instance()->action;
+ $task = rcmail::get_instance()->task;
+ if($action){
+ $start_string .= "Action: ".$action.". ";
+ }
+ if($task){
+ $start_string .= "Task: ".$task.". ";
+ }
+ $this->runlog->start($start_string);
+
+ $this->add_hook('console', array($this, 'console'));
+ $this->add_hook('authenticate', array($this, 'authenticate'));
+ }
+
+ function authenticate($args){
+ $this->runlog->note('Authenticating '.$args['user'].'@'.$args['host']);
+ return $args;
+ }
+
+ function console($args){
+ $note = $args[0];
+ $type = $args[1];
+
+
+ if(!isset($args[1])){
+ // This could be extended to detect types based on the
+ // file which called console. For now only rcube_imap/rcube_storage is supported
+ $bt = debug_backtrace();
+ $file = $bt[3]['file'];
+ switch(basename($file)){
+ case 'rcube_imap.php':
+ $type = 'imap';
+ break;
+ case 'rcube_storage.php':
+ $type = 'storage';
+ break;
+ default:
+ $type = FALSE;
+ break;
+ }
+ }
+ switch($note){
+ case 'end':
+ $type = 'end';
+ break;
+ }
+
+
+ switch($type){
+ case 'start':
+ $this->runlog->start($note);
+ break;
+ case 'end':
+ $this->runlog->end();
+ break;
+ default:
+ $this->runlog->note($note, $type);
+ break;
+ }
+ return $args;
+ }
+
+ function __destruct()
+ {
+ if ($this->runlog)
+ $this->runlog->end();
+ }
+}