From MozillaZine Knowledge Base
Jump to navigationJump to search
|
|
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