MozillaZine

Dev : Tips : Printing to JSConsole

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 23:59, 13 August 2004
Asqueella (Talk | contribs)
(markup + link)
<-- Previous diff
Revision as of 13:02, 4 October 2004
Asqueella (Talk | contribs)
(move to Extensions : Example Code)
Next diff -->
Line 1: Line 1:
-You can output information to console using the following method:+#REDIRECT [[Dev : Extensions : Example Code : Printing to JSConsole]]
- +
-<ul>+
-<li>Declare global variable gConsoleService:+
- var gConsoleService;+
-</li>+
-<li>Initialize it [[Dev : Extensions : onLoad|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)+
-</li>+
-<li>Define a function:+
- function MyApp_logMessage(aMessage) {+
- gConsoleService.logStringMessage('MyApp: ' + aMessage);+
- }+
-</li>+
-<li>Use it like here:+
- MyApp_logMessage('Initialized.');+
-</li>+
-</ul>+
- +
-See also: [[Dev : Tips : Enabling dump|Using dump()]]+
- +
-Reference: [http://www.mozilla.org/projects/xpcom/using-consoleservice.html]+

Revision as of 13:02, 4 October 2004

  1. REDIRECT Dev : Extensions : Example Code : Printing to JSConsole