From MozillaZine Knowledge Base
Jump to navigationJump to search
|
|
(2 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
| You can output information to console using the following method:
| | #REDIRECT [[Error Console]] |
| | |
| <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]
| |
Latest revision as of 20:55, 30 April 2009