feat(core) Add possibility to log debug output

issue #6065
parent 03bfeb94
......@@ -334,6 +334,12 @@ attributetype ( 1.3.6.1.4.1.38414.8.16.4 NAME 'fdDebugLevel'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.8.16.5 NAME 'fdDebugLogging'
DESC 'FusionDirectory - Debug logging'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
# Snapshots
attributetype ( 1.3.6.1.4.1.38414.8.17.1 NAME 'fdEnableSnapshots'
......@@ -599,7 +605,7 @@ objectclass ( 1.3.6.1.4.1.38414.8.2.1 NAME 'fusionDirectoryConf'
fdModificationDetectionAttribute $ fdLogging $ fdLdapSizeLimit $ fdWildcardForeignKeys $
fdLoginAttribute $ fdForceSSL $ fdWarnSSL $ fdStoreFilterSettings $ fdSessionLifeTime $
fdHttpAuthActivated $ fdHttpHeaderAuthActivated $ fdHttpHeaderAuthHeaderName $
fdDisplayErrors $ fdLdapMaxQueryTime $ fdLdapStats $ fdDebugLevel $
fdDisplayErrors $ fdLdapMaxQueryTime $ fdLdapStats $ fdDebugLevel $ fdDebugLogging $
fdEnableSnapshots $ fdSnapshotBase $
fdTabHook $ fdShells $ fdDefaultShell $ fdDisplayHookOutput $
fdPluginsMenuBlacklist $ fdManagementConfig $ fdManagementUserConfig $
......
......@@ -88,6 +88,66 @@ class logging
}
}
/*!
* \brief Debug output method
*
* Print a DEBUG level if specified debug level of the level matches the
* the configured debug level.
*
* \param int $level The log level of the message (one of the DEBUG_* constants)
*
* \param int $line Line of origin (using __LINE__ is common)
*
* \param string $function Function of origin (using __FUNCTION__ is common)
*
* \param string $file File of origin (using __FILE__ is common)
*
* \param mixed $data Operation result. Can be a message or an array, which is printed with print_a.
*
* \param string $info Operation description
*/
static function debug (int $level, int $line, string $function, string $file, $data, string $info = '')
{
global $config;
static $first = TRUE;
if (($_SERVER['REQUEST_METHOD'] == 'POST') && preg_match('/index.php$/', $_SERVER['REQUEST_URI'])) {
return;
}
if (session::get('DEBUGLEVEL') & $level) {
if ($first) {
echo '<div id="debug-handling" class="notice">'.
'<img src="geticon.php?context=status&amp;icon=dialog-information&amp;size=22" alt="Information" style="vertical-align:middle;margin-right:.2em;"/>'.
'There is some debug output '.
'<button onClick="javascript:$$(\'div.debug_div\').each(function (a) { a.toggle(); });">Toggle</button>'.
'</div>';
$first = FALSE;
}
$output = "DEBUG[$level] ";
if ($function != '') {
$output .= "($file:$function():$line) - $info: ";
} else {
$output .= "($file:$line) - $info: ";
}
echo '<div class="debug_div">';
echo $output;
$logline = $output;
if (is_array($data)) {
print_a($data);
$logline .= print_r($data, TRUE);
} else {
echo "'$data'";
$logline .= "'$data'";
}
echo "</div>\n";
if (is_object($config) && preg_match('/true/i', $config->get_cfg_value('debugLogging', ''))) {
fusiondirectory_log($logline);
}
}
}
/*!
* \brief Check the options
*
......
......@@ -172,34 +172,7 @@ function plugin_available ($plugin)
*/
function DEBUG ($level, $line, $function, $file, $data, $info = '')
{
static $first = TRUE;
if (($_SERVER['REQUEST_METHOD'] == 'POST') && preg_match('/index.php$/', $_SERVER['REQUEST_URI'])) {
return;
}
if (session::get('DEBUGLEVEL') & $level) {
if ($first) {
echo '<div id="debug-handling" class="notice">'.
'<img src="geticon.php?context=status&amp;icon=dialog-information&amp;size=22" alt="Information" style="vertical-align:middle;margin-right:.2em;"/>'.
'There is some debug output '.
'<button onClick="javascript:$$(\'div.debug_div\').each(function (a) { a.toggle(); });">Toggle</button>'.
'</div>';
$first = FALSE;
}
$output = "DEBUG[$level] ";
if ($function != '') {
$output .= "($file:$function():$line) - $info: ";
} else {
$output .= "($file:$line) - $info: ";
}
echo '<div class="debug_div">';
echo $output;
if (is_array($data)) {
print_a($data);
} else {
echo "'$data'";
}
echo "</div>\n";
}
logging::debug($level, $line, $function, $file, $data, $info);
}
/*!
......
......@@ -323,6 +323,11 @@ class configInLdap extends simplePlugin
'SESSION', 'ACL', 'SI', 'Mail']
)
),
new BooleanAttribute(
_('Log debug messages'),
_('Sends debug output to syslog as well'),
'fdDebugLogging'
),
]
],
'miscellaneous' => [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment