Error Console

From MozillaZine Knowledge Base
Revision as of 13:18, 4 October 2004 by Asqueella (talk | contribs) (change formatting to <pre>)
Jump to navigationJump to search

You can output information to console using the following method:

  • Declare global variable gConsoleService:
    var gConsoleService;
  • Initialize it on load:
    gConsoleService = 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 MyApp_logMessage(aMessage) {
      gConsoleService.logStringMessage('MyApp: ' + aMessage);
    }
  • Use it like here:
    MyApp_logMessage('Initialized.');

See also: Using dump(), Using Console Service.