- Logging in Firebug (with String Substitution pattern )
- Grouping the logs or messages
- console.dir and console.dirxml
- Assertion ( console.assert() )
- Tracing ( console.trace() )
- Timing ( Measuring the time of your code)
- Javascript Profiler (An introduction in this tutorial, the details will be covered in next tutorial.)
- console.log : Write a message without icon.
- console.debug : Writes a message to the console, including a hyperlink to the line where it was called
console.error() : Writes a message to the console with the visual “error” icon and color coding and a hyperlink to the line where it was called.
console.info() : Writes a message to the console with the visual “info” icon and color coding and a hyperlink to the line where it was called.
console.warn() : Writes a message to the console with the visual “warning” icon and color coding and a hyperlink to the line where it was called.
- Open the htm file called “Plain HTML” or create one HTML file.
- Paste the following code with <body> tag.
1
2
3
4
5
6
7
| <script language="javascript" type="text/javascript">console.log('This is log message');console.debug('This is debug message');console.error('This is error message');console.info('This is info message');console.warn('This is warning message');</script> |

| %s | String |
| %d, %i | Integer (numeric formatting is not yet supported) |
| %f | Floating point number (numeric formatting is not yet supported) |
| %o | Object hyperlink |
- Remove “script” tag that we pasted for the previous example.
- Paste the code below within <body> tag.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| <script language="javascript" type="text/javascript">//This is for normal string substitution " %s, %d, %i, %f".console.log("My Name is <strong>%s</strong>. My Date of Birth is <strong>%dth %s, %i</strong>. My height is <strong>%f</strong> m.", "Nicolas Cage", 7, 'January', 1964, 1.8542);function Foo(){this.LeftHand = function(){return "Left Hand";}this.RightHand = function(){return "Right Hand";}}//This is for object "%o".var objFoo = new Foo();console.log('This is <strong>%o</strong> of Foo class.', objFoo);</script> |

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| <script language="javascript" type="text/javascript">var groupname = 'group1';console.group("message group : %s " , groupname);console.log("log message 1 from %s", groupname);console.log("log message 2 from %s", groupname);console.log("log message 3 from %s", groupname);console.groupEnd();groupname = 'group2';console.group("message group : %s " , groupname);console.log("log message 1 from %s", groupname);var subgroupname = 'subgroup1';console.group("message group : %s " , subgroupname);console.log("log message 1 from %s", subgroupname);console.log("log message 2 from %s", subgroupname);console.log("log message 3 from %s", subgroupname);console.groupEnd();console.log("log message 3 from %s", groupname);console.groupEnd();</script> |

- console.dir : It can be used for getting all properties and methods of a particular object. According the example below, we can get the Model (property) and getManufactor (method) of Car object by using console.dir(); You can also pass the object of HTML element (eg: console.dir(document.getElementById(‘tbl1′)); ) instead of objCar and let’s see the result. (You will get all properties and methods of the HTML table called “tbl1″).
- console.dirxml : print the XML source tree of HTML element.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| <table id="tbl1" cellpadding="0" cellspacing="0" border="0"><tr><td>A</td><td>B</td><td>C</td></tr></table><script language="javascript" type="text/javascript">//Create a classfunction Car(){this.Model = "Old Model";this.getManufactor = new function(){return "Toyota";}}//Create a objectvar objCar = new Car();//Firebugconsole.dir(objCar);console.dirxml(document.getElementById('tbl1'));</script> |

1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <script language="javascript" type="text/javascript">function whatIsMyAge(year){var currYear = 2007;return currYear - year;}var yearOfBirth1 = 1982;var age1 = 25;console.assert(whatIsMyAge(yearOfBirth1) == age1);var yearOfBirth2 = 1982;var age2 = 11;console.assert(whatIsMyAge(yearOfBirth2) == age2); //You should get the error here.</script> |

CONSOLE.TRACE()
Prints an interactive stack trace of JavaScript execution at the point where it is called.The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function. You can click each function to take you to its source in the Script tab, and click each argument value to inspect it in the DOM or HTML tabs.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head><title>Firebug</title><script language="javascript" type="text/javascript">function startTrace(str){return method1(100,200);}function method1(arg1,arg2){return method2(arg1 + arg2 + 100);}function method2(arg1){var var1 = arg1 / 100;return method3(var1);}function method3(arg1){console.trace();var total = arg1 * 100;return total;}</script></head><body><input type="button" value="Trace" onclick="startTrace('Result');"/></body></html> |

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head><title>Firebug</title><script language="javascript" type="text/javascript">function measuretheTime(){var timeName = 'measuringTime';console.time(timeName);for(var i=0;i<1000;i++){///do somethingfor(var j=0;j<100;j++){//do another thing.}}console.timeEnd(timeName);}</script></head><body><input type="button" value="Trace" onclick="measuretheTime();"/></body></html> |