From d8d28d63504a926007f880ae2973874f7f8af770 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Aug 2012 17:43:20 +0200 Subject: [PATCH] New: Add ChromePHP output into syslog module. --- ChangeLog | 1 + htdocs/admin/syslog.php | 42 ++++++++++++++++++++++++++++--- htdocs/core/lib/functions.lib.php | 26 +++++++++++++++++-- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c31ad7e3b5..aec1ba17023 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,7 @@ For developers: - New: Basic implementation of hooks and triggers for a lot (most) of core modules: action/calendar, trips and expenses, dons, vat payment, contact/society, contract, product lines, expedition, order supplier and order invoice (lines included), intervention card, project, tasks. +- New: Add ChromePHP output into syslog module. For translators: - New: Update language files (de, tr, pt, ca, es, en, fr). diff --git a/htdocs/admin/syslog.php b/htdocs/admin/syslog.php index 312a99649c2..d1abf15f345 100644 --- a/htdocs/admin/syslog.php +++ b/htdocs/admin/syslog.php @@ -35,7 +35,8 @@ $error=0; $mesg=''; $action = GETPOST("action"); $syslog_file_on=(defined('SYSLOG_FILE_ON') && constant('SYSLOG_FILE_ON'))?1:0; $syslog_syslog_on=(defined('SYSLOG_SYSLOG_ON') && constant('SYSLOG_SYSLOG_ON'))?1:0; -$syslog_firephp_on=(defined('SYSLOG_FIREPHP_ON') && constant('SYSLOG_FIREPHP_ON'))?1:0; +$syslog_firephp_on=(defined('SYSLOG_FIREPHP_ON') && constant('SYSLOG_FIREPHP_ON'))?1:0; +$syslog_chromephp_on=(defined('SYSLOG_CHROMEPHP_ON') && constant('SYSLOG_CHROMEPHP_ON'))?1:0; /* @@ -54,6 +55,7 @@ if ($action == 'set') $syslog_file_on=0; $syslog_syslog_on=0; $syslog_firephp_on=0; + $syslog_chromephp_on=0; if (! $error && GETPOST("filename")) { @@ -99,13 +101,19 @@ if ($action == 'set') } } - if (! $error && isset($_POST['SYSLOG_FIREPHP_ON'])) // If firephp no available, post is not present + if (! $error && isset($_POST['SYSLOG_FIREPHP_ON'])) // If firephp no available, post is not present. We must keep isset here. { $syslog_firephp_on=GETPOST('SYSLOG_FIREPHP_ON'); if (! $error) $res = dolibarr_set_const($db,"SYSLOG_FIREPHP_ON",$syslog_firephp_on,'chaine',0,'',0); } - if (! $error) + if (! $error && isset($_POST['SYSLOG_CHROMEPHP_ON'])) // If chromephp no available, post is not present. We must keep isset here. + { + $syslog_chromephp_on=GETPOST('SYSLOG_CHROMEPHP_ON'); + if (! $error) $res = dolibarr_set_const($db,"SYSLOG_CHROMEPHP_ON",$syslog_chromephp_on,'chaine',0,'',0); + } + + if (! $error) { $db->commit(); $mesg = "".$langs->trans("SetupSaved").""; @@ -176,6 +184,7 @@ print '\n"; $var=true; +// Output to file $var=!$var; print ' '.$langs->trans("SyslogSimpleFile").''; print ''.$langs->trans("SyslogFilename").': '; @@ -183,6 +192,7 @@ print ''; print "".$form->textwithpicto('',$langs->trans("YouCanUseDOL_DATA_ROOT")); print ''; +// Output to syslog $var=!$var; print ' '.$langs->trans("SyslogSyslog").''; print ''.$langs->trans("SyslogFacility").': '; @@ -190,6 +200,7 @@ print ''; print "".$form->textwithpicto('', $langs->trans('OnlyWindowsLOG_USER')); print ''; +// Output to Firebug try { set_include_path('/usr/share/php/'); @@ -214,6 +225,31 @@ catch(Exception $e) print ''."\n"; } +// Output to Chrome +try +{ + set_include_path('/usr/share/php/'); + $res=@include_once 'ChromePhp.php'; + restore_include_path(); + if ($res) + { + $var=!$var; + print ' '.$langs->trans("ChromePHP").''; + print ''; + print ''; + print "".$form->textwithpicto('','ChromePHP must be installed onto PHP path and ChromePHP plugin for Chrome must also be installed'); + print ''; + } +} +catch(Exception $e) +{ + // Do nothing + print ''."\n"; +} + print "\n"; print "\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 790d8580b93..cccc2429817 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -570,7 +570,7 @@ function dol_syslog($message, $level=LOG_INFO) set_include_path('/usr/share/php/'); include_once 'FirePHPCore/FirePHP.class.php'; set_include_path($oldinclude); - ob_start(); + ob_start(); // To be sure headers are not flushed until all page is completely processed $firephp = FirePHP::getInstance(true); if ($level == LOG_ERR) $firephp->error($message); elseif ($level == LOG_WARNING) $firephp->warn($message); @@ -579,7 +579,29 @@ function dol_syslog($message, $level=LOG_INFO) } catch(Exception $e) { - // Do not use dol_syslog to avoid infinite loop + // Do not use dol_syslog here to avoid infinite loop + } + } + // Check if log is to syslog (SYSLOG_FIREPHP_ON defined) + if (defined("SYSLOG_CHROMEPHP_ON") && constant("SYSLOG_CHROMEPHP_ON") && ! empty($_SERVER["SERVER_NAME"])) //! empty($_SERVER["SERVER_NAME"]) to be sure to enable this in Web mode only + { + try + { + // Warning ChromePHP must be into PHP include path. It is not possible to use into require_once() a constant from + // database or config file because we must be able to log data before database or config file read. + $oldinclude=get_include_path(); + set_include_path('/usr/share/php/'); + include_once 'ChromePhp.php'; + set_include_path($oldinclude); + ob_start(); // To be sure headers are not flushed until all page is completely processed + if ($level == LOG_ERR) ChromePhp::error($message); + elseif ($level == LOG_WARNING) ChromePhp::warn($message); + elseif ($level == LOG_INFO) ChromePhp::log($message); + else ChromePhp::log($message); + } + catch(Exception $e) + { + // Do not use dol_syslog here to avoid infinite loop } } }