Skip to content

Instantly share code, notes, and snippets.

@snj14
Created September 21, 2008 07:10
Show Gist options
  • Save snj14/11848 to your computer and use it in GitHub Desktop.
Save snj14/11848 to your computer and use it in GitHub Desktop.
log
// this function works on firefox extension.
function log(){
const Ci = Components.interfaces;
const Cc = Components.classes;
function firebug(method, args){
var windowManager = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var win = windowManager.getMostRecentWindow("navigator:browser");
if(win.FirebugConsole && win.FirebugContext) {
var console = new win.FirebugConsole(win.FirebugContext, win.content);
console[method].apply(console, args);
} else if ( (win.Firebug || 0).Console ) {
// Firebug 1.2~
win.Firebug.Console.logFormatted.call(win.Firebug.Console, Array.slice(args), win.FirebugContext, method);
} else {
return false;
}
return true;
}
function lognative(){
const ConsoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
ConsoleService.logStringMessage(arguments);
}
firebug('log',arguments) || lognative(arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment