Trainings

Thursday, June 17, 2010

Logging in Javascript

Using Logging in Javascript
------------------------------
It's very usefull to have logging statement in your code .
console.log(); statement is very handy to log information in javascript .
sample code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function() {
console.log('current value is prashant gupta');
console.info('this is information')
console.warn('this is warning')
console.error('this is error.')
console.debug('this is debug.')

})
</script>


what you need to do is
1. just include the jquery file in your code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
2. and now you can use
console.log("");
for loggin.

How to see the logged statement:
to check javascript logs , I uses Firebug extension in Mozilla.
just see below image how it is easy to see your logs in firebug.......