mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 540633: Label httpd.js debug logs, optionally timestamp them, and add support for enabling or disabling them in the middle of a run (currently only for mochitests). r=jwalden
This commit is contained in:
parent
3415af3075
commit
6f802fa89d
@ -57,6 +57,9 @@ const PR_UINT32_MAX = Math.pow(2, 32) - 1;
|
||||
/** True if debugging output is enabled, false otherwise. */
|
||||
var DEBUG = false; // non-const *only* so tweakable in server tests
|
||||
|
||||
/** True if debugging output should be timestamped. */
|
||||
var DEBUG_TIMESTAMP = false; // non-const so tweakable in server tests
|
||||
|
||||
var gGlobalObject = this;
|
||||
|
||||
/**
|
||||
@ -75,7 +78,7 @@ function NS_ASSERT(cond, msg)
|
||||
|
||||
var stack = new Error().stack.split(/\n/);
|
||||
dumpn(stack.map(function(val) { return "###!!! " + val; }).join("\n"));
|
||||
|
||||
|
||||
throw Cr.NS_ERROR_ABORT;
|
||||
}
|
||||
}
|
||||
@ -164,12 +167,32 @@ const HEADERS_SUFFIX = HIDDEN_CHAR + "headers" + HIDDEN_CHAR;
|
||||
/** Type used to denote SJS scripts for CGI-like functionality. */
|
||||
const SJS_TYPE = "sjs";
|
||||
|
||||
/** Base for relative timestamps produced by dumpn(). */
|
||||
var firstStamp = 0;
|
||||
|
||||
/** dump(str) with a trailing "\n" -- only outputs if DEBUG */
|
||||
/** dump(str) with a trailing "\n" -- only outputs if DEBUG. */
|
||||
function dumpn(str)
|
||||
{
|
||||
if (DEBUG)
|
||||
dump(str + "\n");
|
||||
{
|
||||
var prefix = "HTTPD-INFO | ";
|
||||
if (DEBUG_TIMESTAMP)
|
||||
{
|
||||
if (firstStamp === 0)
|
||||
firstStamp = Date.now();
|
||||
|
||||
var elapsed = Date.now() - firstStamp; // milliseconds
|
||||
var min = Math.floor(elapsed / 60000);
|
||||
var sec = (elapsed % 60000) / 1000;
|
||||
|
||||
if (sec < 10)
|
||||
prefix += min + ":0" + sec.toFixed(3) + " | ";
|
||||
else
|
||||
prefix += min + ":" + sec.toFixed(3) + " | ";
|
||||
}
|
||||
|
||||
dump(prefix + str + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/** Dumps the current JS stack if DEBUG. */
|
||||
|
@ -198,6 +198,7 @@ function createMochitestServer(serverBasePath)
|
||||
|
||||
server.registerDirectory("/", serverBasePath);
|
||||
server.registerPathHandler("/server/shutdown", serverShutdown);
|
||||
server.registerPathHandler("/server/debug", serverDebug);
|
||||
server.registerContentType("sjs", "sjs"); // .sjs == CGI-like functionality
|
||||
server.registerContentType("jar", "application/x-jar");
|
||||
server.registerContentType("ogg", "application/ogg");
|
||||
@ -310,6 +311,39 @@ function serverShutdown(metadata, response)
|
||||
server.stop(serverStopped);
|
||||
}
|
||||
|
||||
// /server/debug?[012]
|
||||
function serverDebug(metadata, response)
|
||||
{
|
||||
response.setStatusLine(metadata.httpVersion, 400, "Bad debugging level");
|
||||
if (metadata.queryString.length !== 1)
|
||||
return;
|
||||
|
||||
var mode;
|
||||
if (metadata.queryString === "0") {
|
||||
// do this now so it gets logged with the old mode
|
||||
dumpn("Server debug logs disabled.");
|
||||
DEBUG = false;
|
||||
DEBUG_TIMESTAMP = false;
|
||||
mode = "disabled";
|
||||
} else if (metadata.queryString === "1") {
|
||||
DEBUG = true;
|
||||
DEBUG_TIMESTAMP = false;
|
||||
mode = "enabled";
|
||||
} else if (metadata.queryString === "2") {
|
||||
DEBUG = true;
|
||||
DEBUG_TIMESTAMP = true;
|
||||
mode = "enabled, with timestamps";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
||||
response.setHeader("Content-type", "text/plain", false);
|
||||
var body = "Server debug logs " + mode + ".";
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
dumpn(body);
|
||||
}
|
||||
|
||||
//
|
||||
// DIRECTORY LISTINGS
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user