None

Firebug Console Functions

February 19, 2010

The firebug plugin to firefox supports a variety of different functions which can be used for debugging and profiling a web app.

Logging

You can log messages at different levels, just like log4j.

console.log("Hello World");
console.debug("Debug Output");
console.warn("Danger, Will Robinson");
console.error("Sorry, it's gone wrong");
console.info("Information");

The first two of these log normally with black on white text. The warn() message has a yellow ! icon and a blue background. The error() has a red cross icon and a pale yellow background. The info() function has a blue i icon, and logs as black on white.

You can specify multiple parameters, they are all added together in the output:

var drum = "snare";
var percussion = {instrument: "Djembe"};
var kit = function() { return "five piece" };

console.log("Hello World - ", drum, ":", percussion, kit);

will output Hello World - snare : Object instrument=Djembe function()

Tracing

There's a command that will output a stack trace to the console:

console.trace()

Counting

There's a function to count, with a human readable label:

console.count("Fred");
console.count("Fred");
console.count("Fred");
console.count("Edith");
console.count("Edith");
console.count("Fred");

outputs:

Fred 4
Edith 2

Timing

time() and timeEnd() can be used to find out how long a particular section of code takes:

console.time("Counting");
console.count("Fred");
console.count("Fred");
console.count("Fred");
console.count("Edith");
console.count("Edith");
console.count("Fred");
console.timeEnd("Counting");

outputs:

Counting: 5ms

Profiling

The profile() and profileEnd() functions can be used to produce a detailed breakdown of where the time went.

console.profile("Counting");
console.count("Fred");
console.count("Fred");
console.count("Fred");
console.count("Edith");
console.count("Edith");
console.count("Fred");
console.profileEnd("Counting");

This outputs a table in the firebug console that contains the Function, number of calls, percent of time taken, actual and average times taken.