From 78d9ac01d95ff4aa9a8cafdd670b0bba41cf9bde Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 28 Aug 2008 14:58:49 +0200 Subject: [PATCH] Added option to send debug messages from phpLogCon to local syslog server On Linux, the debug messages (warnings and error's for now) will be send to the local syslog server. On Windows, the debug messages will appear in the windows application eventlog. --- src/admin/index.php | 8 ++++-- .../logstreamlineparsersyslog.class.php | 2 +- .../logstreamlineparserwinsyslog.class.php | 2 +- src/include/config.sample.php | 1 + src/include/functions_common.php | 13 +++++++-- src/include/functions_filters.php | 2 +- src/include/functions_frontendhelpers.php | 28 ++++++++++++++++++- src/lang/de/admin.php | 3 +- src/lang/en/admin.php | 3 +- src/lang/pt_BR/admin.php | 3 +- src/templates/admin/admin_index.html | 13 ++++++--- 11 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/admin/index.php b/src/admin/index.php index 6a277af..8a76a2d 100644 --- a/src/admin/index.php +++ b/src/admin/index.php @@ -132,8 +132,9 @@ if ( isset($_POST['op']) ) if ( isset ($_POST['MiscShowDebugGridCounter']) ) { $content['MiscShowDebugGridCounter'] = 1; } else { $content['MiscShowDebugGridCounter'] = 0; } if ( isset ($_POST['MiscShowPageRenderStats']) ) { $content['MiscShowPageRenderStats'] = 1; } else { $content['MiscShowPageRenderStats'] = 0; } if ( isset ($_POST['MiscEnableGzipCompression']) ) { $content['MiscEnableGzipCompression'] = 1; } else { $content['MiscEnableGzipCompression'] = 0; } - if ( isset ($_POST['DebugUserLogin']) ) { $content['DebugUserLogin'] = 1; } else { $content['DebugUserLogin'] = 0; } if ( isset ($_POST['SuppressDuplicatedMessages']) ) { $content['SuppressDuplicatedMessages'] = 1; } else { $content['SuppressDuplicatedMessages'] = 0; } + if ( isset ($_POST['DebugUserLogin']) ) { $content['DebugUserLogin'] = 1; } else { $content['DebugUserLogin'] = 0; } + if ( isset ($_POST['MiscDebugToSyslog']) ) { $content['MiscDebugToSyslog'] = 1; } else { $content['MiscDebugToSyslog'] = 0; } // Read Text number fields if ( isset ($_POST['ViewMessageCharacterLimit']) && is_numeric($_POST['ViewMessageCharacterLimit']) ) { $content['ViewMessageCharacterLimit'] = $_POST['ViewMessageCharacterLimit']; } @@ -177,7 +178,6 @@ if ( isset($_POST['op']) ) if ( isset ($_POST['User_MiscShowDebugGridCounter']) ) { $USERCFG['MiscShowDebugGridCounter'] = 1; } else { $USERCFG['MiscShowDebugGridCounter'] = 0; } if ( isset ($_POST['User_MiscShowPageRenderStats']) ) { $USERCFG['MiscShowPageRenderStats'] = 1; } else { $USERCFG['MiscShowPageRenderStats'] = 0; } if ( isset ($_POST['User_MiscEnableGzipCompression']) ) { $USERCFG['MiscEnableGzipCompression'] = 1; } else { $USERCFG['MiscEnableGzipCompression'] = 0; } -// DISABLED FOR USER! if ( isset ($_POST['User_DebugUserLogin']) ) { $USERCFG['DebugUserLogin'] = 1; } else { $USERCFG['DebugUserLogin'] = 0; } if ( isset ($_POST['User_SuppressDuplicatedMessages']) ) { $USERCFG['SuppressDuplicatedMessages'] = 1; } else { $USERCFG['SuppressDuplicatedMessages'] = 0; } // Read Text number fields @@ -209,8 +209,10 @@ if ($content['MiscShowDebugMsg'] == 1) { $content['MiscShowDebugMsg_checked'] = if ($content['MiscShowDebugGridCounter'] == 1) { $content['MiscShowDebugGridCounter_checked'] = "checked"; } else { $content['MiscShowDebugGridCounter_checked'] = ""; } if ($content['MiscShowPageRenderStats'] == 1) { $content['MiscShowPageRenderStats_checked'] = "checked"; } else { $content['MiscShowPageRenderStats_checked'] = ""; } if ($content['MiscEnableGzipCompression'] == 1) { $content['MiscEnableGzipCompression_checked'] = "checked"; } else { $content['MiscEnableGzipCompression_checked'] = ""; } -if ($content['DebugUserLogin'] == 1) { $content['DebugUserLogin_checked'] = "checked"; } else { $content['DebugUserLogin_checked'] = ""; } if ($content['SuppressDuplicatedMessages'] == 1) { $content['SuppressDuplicatedMessages_checked'] = "checked"; } else { $content['SuppressDuplicatedMessages_checked'] = ""; } + +if ($content['DebugUserLogin'] == 1) { $content['DebugUserLogin_checked'] = "checked"; } else { $content['DebugUserLogin_checked'] = ""; } +if ($content['MiscDebugToSyslog'] == 1) { $content['MiscDebugToSyslog_checked'] = "checked"; } else { $content['MiscDebugToSyslog_checked'] = ""; } // --- // --- Init for Style field! diff --git a/src/classes/logstreamlineparsersyslog.class.php b/src/classes/logstreamlineparsersyslog.class.php index 275e069..7d66b12 100644 --- a/src/classes/logstreamlineparsersyslog.class.php +++ b/src/classes/logstreamlineparsersyslog.class.php @@ -118,7 +118,7 @@ class LogStreamLineParsersyslog extends LogStreamLineParser { else { if ( isset($arrArguments[SYSLOG_MESSAGE]) && strlen($arrArguments[SYSLOG_MESSAGE]) > 0 ) - OutputDebugMessage("Unparseable syslog msg - '" . $arrArguments[SYSLOG_MESSAGE] . "'"); + OutputDebugMessage("Unparseable syslog msg - '" . $arrArguments[SYSLOG_MESSAGE] . "'", DEBUG_ERROR); } // If SyslogTag is set, we check for MessageType! diff --git a/src/classes/logstreamlineparserwinsyslog.class.php b/src/classes/logstreamlineparserwinsyslog.class.php index 35eb8ee..c3b8996 100644 --- a/src/classes/logstreamlineparserwinsyslog.class.php +++ b/src/classes/logstreamlineparserwinsyslog.class.php @@ -88,7 +88,7 @@ class LogStreamLineParserwinsyslog extends LogStreamLineParser { else { if ( isset($arrArguments[SYSLOG_MESSAGE]) && strlen($arrArguments[SYSLOG_MESSAGE]) > 0 ) - OutputDebugMessage("Unparseable Winsyslog message - '" . $arrArguments[SYSLOG_MESSAGE] . "'"); + OutputDebugMessage("Unparseable Winsyslog message - '" . $arrArguments[SYSLOG_MESSAGE] . "'", DEBUG_ERROR); } // If SyslogTag is set, we check for MessageType! diff --git a/src/include/config.sample.php b/src/include/config.sample.php index 4de4764..7fb20f2 100644 --- a/src/include/config.sample.php +++ b/src/include/config.sample.php @@ -54,6 +54,7 @@ $CFG['UserDBLoginRequired'] = false; // --- Misc Options $CFG['MiscShowDebugMsg'] = 0; // if enabled, you will get additional output on certain places +$CFG['MiscDebugToSyslog'] = 0; // if enabled, debug messages from phpLogCon will be send to syslog on linux, and into the EventLog on Windows $CFG['MiscShowDebugGridCounter'] = 0; // Only for debugging purposes, will add a counter column into the grid! $CFG["MiscShowPageRenderStats"] = 1; // If enabled, you will see Pagerender Settings $CFG['MiscEnableGzipCompression'] = 1; // If enabled, phplogcon will use gzip compression for output, we recommend diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 415e6e7..d9c23da 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -388,6 +388,10 @@ function CheckAndSetRunMode() // Obtain max_execution_time $MaxExecutionTime = ini_get("max_execution_time"); + + // Define and Inits Syslog variables now! + define_syslog_variables(); + openlog("phpLogCon", LOG_PID, LOG_USER); // --- Check necessary PHP Extensions! $loadedExtensions = get_loaded_extensions(); @@ -402,7 +406,7 @@ function CheckAndSetRunMode() if ( in_array("mysql", $loadedExtensions) ) { $content['MYSQL_IS_ENABLED'] = true; } else { $content['MYSQL_IS_ENABLED'] = false; } // Check PDO Extension if ( in_array("PDO", $loadedExtensions) ) { $content['PDO_IS_ENABLED'] = true; } else { $content['PDO_IS_ENABLED'] = false; } - + // --- } function InitRuntimeInformations() @@ -878,7 +882,7 @@ function GetEventTime($szTimStr) $eventtime[EVTIME_MICROSECONDS] = 0; // Print Error! - OutputDebugMessage("GetEventTime got an unparsable time '" . $szTimStr . "', returning 0"); + OutputDebugMessage("GetEventTime got an unparsable time '" . $szTimStr . "', returning 0", DEBUG_WARN); } // return result! @@ -1101,7 +1105,6 @@ function SaveGeneralSettingsIntoDB() WriteConfigValue( "MiscShowDebugGridCounter", true ); WriteConfigValue( "MiscShowPageRenderStats", true ); WriteConfigValue( "MiscEnableGzipCompression", true ); - WriteConfigValue( "DebugUserLogin", true ); WriteConfigValue( "SuppressDuplicatedMessages", true ); WriteConfigValue( "ViewMessageCharacterLimit", true ); @@ -1115,6 +1118,10 @@ function SaveGeneralSettingsIntoDB() // Extra Fields WriteConfigValue( "DefaultViewsID", true ); WriteConfigValue( "DefaultSourceID", true ); + + // GLOBAL ONLY + WriteConfigValue( "DebugUserLogin", true ); + WriteConfigValue( "MiscDebugToSyslog", true ); } function SaveUserGeneralSettingsIntoDB() diff --git a/src/include/functions_filters.php b/src/include/functions_filters.php index 810b2dd..b2c4332 100644 --- a/src/include/functions_filters.php +++ b/src/include/functions_filters.php @@ -262,7 +262,7 @@ function GetTimeStampFromTimeString($szTimeString) } else { - OutputDebugMessage("Unparseable Time in GetTimeStampFromTimeString - '" . $szTimeString . "'"); + OutputDebugMessage("Unparseable Time in GetTimeStampFromTimeString - '" . $szTimeString . "'", DEBUG_WARN); return $szTimeString; } } diff --git a/src/include/functions_frontendhelpers.php b/src/include/functions_frontendhelpers.php index e357369..f288124 100644 --- a/src/include/functions_frontendhelpers.php +++ b/src/include/functions_frontendhelpers.php @@ -232,8 +232,9 @@ function GetFormatedDate($evttimearray) return $szDateFormatted = date("Y-m-d H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); } -function OutputDebugMessage($szDbg) +function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) { + // Check if we should print the Error! if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 ) { print(""); @@ -241,6 +242,31 @@ function OutputDebugMessage($szDbg) print(""); print("
" . $szDbg . "

"); } + + // Check if the user wants to syslog the error! + if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 ) + { + syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); + } +} + +function GetPriorityFromDebugLevel( $DebugLevel ) +{ + switch ( $DebugLevel ) + { + case DEBUG_ULTRADEBUG: + return LOG_DEBUG; + case DEBUG_DEBUG: + return LOG_INFO; + case DEBUG_INFO: + return LOG_NOTICE; + case DEBUG_WARN: + return LOG_WARNING; + case DEBUG_ERROR: + return LOG_ERR; + case DEBUG_ERROR_WTF: + return LOG_CRIT; + } } ?> \ No newline at end of file diff --git a/src/lang/de/admin.php b/src/lang/de/admin.php index 210c36d..38a15dc 100644 --- a/src/lang/de/admin.php +++ b/src/lang/de/admin.php @@ -83,7 +83,8 @@ $content['LN_GEN_GLOBALVALUE'] = "Global value"; $content['LN_GEN_PERSONALVALUE'] = "Personal (User)value"; $content['LN_GEN_DISABLEUSEROPTIONS'] = "Click here to disable personal options"; $content['LN_GEN_ENABLEUSEROPTIONS'] = "Click here to enable personal options"; - +$content['LN_ADMIN_GLOBALONLY'] = "Global Options Only"; +$content['LN_GEN_DEBUGTOSYSLOG'] = "Send Debug to local syslog server"; // User Center $content['LN_USER_CENTER'] = "User Options"; diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index 210c36d..38a15dc 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -83,7 +83,8 @@ $content['LN_GEN_GLOBALVALUE'] = "Global value"; $content['LN_GEN_PERSONALVALUE'] = "Personal (User)value"; $content['LN_GEN_DISABLEUSEROPTIONS'] = "Click here to disable personal options"; $content['LN_GEN_ENABLEUSEROPTIONS'] = "Click here to enable personal options"; - +$content['LN_ADMIN_GLOBALONLY'] = "Global Options Only"; +$content['LN_GEN_DEBUGTOSYSLOG'] = "Send Debug to local syslog server"; // User Center $content['LN_USER_CENTER'] = "User Options"; diff --git a/src/lang/pt_BR/admin.php b/src/lang/pt_BR/admin.php index c04ceb3..451a150 100644 --- a/src/lang/pt_BR/admin.php +++ b/src/lang/pt_BR/admin.php @@ -53,7 +53,8 @@ $content['LN_GEN_GLOBALVALUE'] = "Global value"; $content['LN_GEN_PERSONALVALUE'] = "Personal (User)value"; $content['LN_GEN_DISABLEUSEROPTIONS'] = "Click here to disable personal options"; $content['LN_GEN_ENABLEUSEROPTIONS'] = "Click here to enable personal options"; - +$content['LN_ADMIN_GLOBALONLY'] = "Global Options Only"; +$content['LN_GEN_DEBUGTOSYSLOG'] = "Send Debug to local syslog server"; // General Options $content['LN_ADMIN_GLOBFRONTEND'] = "Global frontend options"; diff --git a/src/templates/admin/admin_index.html b/src/templates/admin/admin_index.html index 77a0151..ca06bc4 100644 --- a/src/templates/admin/admin_index.html +++ b/src/templates/admin/admin_index.html @@ -211,12 +211,17 @@ + + + {LN_ADMIN_GLOBALONLY} + {LN_GEN_DEBUGUSERLOGIN} - - -   - + + + + {LN_GEN_DEBUGTOSYSLOG} +