So I doubt this is the best way to use Firebug logging in an
extension, but it works. The log appears in the Firebug context for
the currently focused window. In the case that Firebug is disabled or
you need logging for browser startup, it also logs to the Firefox
console.
function debug(aMessage) {
try {
var objects = [];
objects.push.apply(objects, arguments);
Firebug.Console.logFormatted(objects,
TabWatcher.getContextByWindow
(content.document.defaultView.wrappedJSObject));
}
catch (e) {
}
var consoleService = Components.classes["@
mozilla.org/
consoleservice;1"].getService
(Components.interfaces.nsIConsoleService);
if (aMessage === "") consoleService.logStringMessage
("(empty string)");
else if (aMessage != null) consoleService.logStringMessage
(aMessage.toString());
else consoleService.logStringMessage("null");
}