Dev : Tips : Printing to JSConsole
From MozillaZine Knowledge Base
You can output information to console using the following method:
- Declare global variable aConsoleService:
var aConsoleService;
- Initialize it on load:
aConsoleService = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
(note, you can also use toJavaScriptConsole() function to open JavaScript console on startup)
- Define a function:
function logMessage(message) { aConsoleService.logStringMessage('MyApp: ' + message); }
- Use it like here:
logMessage('Initialized.');
(thanks to clav, velcrospud and sage.mozdev.org for this)
See also: Using dump()