Dev : Tips : Printing to JSConsole: Difference between revisions
From MozillaZine Knowledge Base
Jump to navigationJump to search
Torisugari (talk | contribs) m (naming convention) |
Torisugari (talk | contribs) mNo edit summary |
||
Line 8: | Line 8: | ||
(note, you can also use toJavaScriptConsole() function to open JavaScript console on startup) | (note, you can also use toJavaScriptConsole() function to open JavaScript console on startup) | ||
*Define a function: | *Define a function: | ||
function | function MyApp_logMessage(aMessage) { | ||
gConsoleService.logStringMessage('MyApp: ' + | gConsoleService.logStringMessage('MyApp: ' + aMessage); | ||
} | } | ||
*Use it like here: | *Use it like here: | ||
MyApp_logMessage('Initialized.'); | |||
(thanks to clav, velcrospud and sage.mozdev.org for this) | (thanks to clav, velcrospud and sage.mozdev.org for this) | ||
See also: [[Dev : Tips : Enabling dump|Using dump()]] | See also: [[Dev : Tips : Enabling dump|Using dump()]] |
Revision as of 21:46, 11 July 2004
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.');
(thanks to clav, velcrospud and sage.mozdev.org for this)
See also: Using dump()