MozillaZine

Dev : Tips : Printing to JSConsole

From MozillaZine Knowledge Base

(Difference between revisions)

Revision as of 19:55, 10 July 2004

You can output information to console using the following method:

  • Declare global variable aConsoleService:
var aConsoleService;
aConsoleService = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
  • Define a function:
function logMessage(message) {
  aConsoleService.logStringMessage('MyApp: ' + message);
}
  • Use it like here:
logMessage('Initialized.');

See also: Using dump()