The ADODB custom logger isn't necessarily appropriate for main inclusion. Though, I think teaching people about the possibility of debug logging to a file would be helpful because it is hard to use OJS while it's dumping lots of SQL above every page. The code is commented in the patch; so even after applied, it requires user intervention.
The stacktrace to log file functionality would be a big help, however. I'm sure this code isn't great, but maybe it's a start toward inclusion. You must add "stacktrace_to_logfile = On" to config.inc.php.
Thoughts?
- Code: Select all
--- ojs-2.2.2-clean/index.php 2008-11-18 10:54:24.000000000 -0500
+++ ojs-2.2.2-test/index.php 2008-11-18 15:40:36.000000000 -0500
@@ -52,6 +52,26 @@
// $Id: index.php,v 1.23 2008/07/01 01:16:09 asmecher Exp $
+/*
+ * Uncomment the code immediately below and set "debug = On" in your "config.inc.php".
+ *
+ * Define a custom ADODB error log function. See: "lib/adodb/adodb.inc.php".
+ * Unfortunately, HTML is inserted into the error message by _adodb_debug_execute(),
+ * in lib/adodb/adodb-lib.inc.php; crudely remove it for log readability.
+ * (We can't "unset($_SERVER['HTTP_USER_AGENT']", because that will break OJS.)
+ */
+/*
+$GLOBALS['ADODB_OUTP'] = 'ojsLogSql';
+
+function ojsLogSql ($msg, $newline) {
+ $msg = str_replace( array(' ', '<code>', '</code>', '<hr />'), "", $msg);
+ $msg = htmlspecialchars_decode($msg);
+ error_log("$msg $newline");
+}
+
+*/
+
+
/**
* Handle a new request.
*/
- Code: Select all
--- ojs-2.2.2-clean/includes/functions.inc.php 2008-06-30 21:16:11.000000000 -0400
+++ ojs-2.2.2-test/includes/functions.inc.php 2008-11-18 15:33:21.000000000 -0500
@@ -83,10 +83,10 @@
$isErrorCondition = false;
}
- echo "<h1>$reason</h1>";
+ $stackTraceOutput[] = "$reason";
if ($showStackTrace && checkPhpVersion('4.3.0')) {
- echo "<h4>Stack Trace:</h4>\n";
+
$trace = debug_backtrace();
// Remove the call to fatalError from the call trace.
@@ -138,13 +138,46 @@
$file = isset($bt['file'])?$bt['file']:'(unknown)';
$line = isset($bt['line'])?$bt['line']:'(unknown)';
- echo "<strong>File:</strong> {$file} line {$line}<br />\n";
- echo "<strong>Function:</strong> {$class}{$type}{$function}($args)<br />\n";
+ // Record all the trace information as an array in the main output array.
+ $stacktraceOutput[] = array($file, $line, $class, $type, $function, $args);
+ }
+ }
+
+ // Check the destination of the stack trace output.
+ $stackTraceToLogfile = Config::getVar('debug', 'stacktrace_to_logfile');
+
+ // If the destination is the log file, plain print information without markup.
+ if ($stackTraceToLogfile) {
+
+ // The first element is the $reason, and we only print it once.
+ error_log("OJS Fatal Error: $stackTraceOutput[0]\n");
+ array_shift($stackTraceOutput);
+
+ // The remaining elements are each an array containing trace specific output; iterate over them.
+ foreach ($stackTraceOutput as $traceOutput) {
+ echo "Stack Trace:\n";
+ echo "File: {$traceOutput[0]} line {$traceOutput[1]}\n";
+ echo "Function: {$traceOutput[2]}{$traceOutput[3]}{$traceOutput[4]}($traceOutput[5])\n";
+ }
+
+ // Else, the destination is the browser, print HTML.
+ } else {
+ // Even if the stacktrace is going to the browser, put short note in the log file.
+ error_log("OJS Fatal Error: $stackTraceOutput[0]\n");
+
+ // The first element is the $reason, and we only print it once.
+ echo "<h1>$stackTraceOutput[0]</h1>";
+ array_shift($stackTraceOutput);
+
+ // The remaining elements are each an array containing trace specific output; iterate over them.
+ foreach ($stackTraceOutput as $traceOutput) {
+ echo "<h4>Stack Trace:</h4>\n";
+ echo "<strong>File:</strong> {$traceOutput[0]} line {$traceOutput[1]}<br />\n";
+ echo "<strong>Function:</strong> {$traceOutput[2]}{$traceOutput[3]}{$traceOutput[4]}($traceOutput[5])<br />\n";
echo "<br/>\n";
}
}
- error_log("OJS: $reason");
die();
}
