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.......

1 comment:

  1. Most of these utilities shrink the JavaScript via minification. The exception to this is Packer, which generates a self extracting package. Where minified JavaScript can be cached, the Packer compressed script has runtime overheads as it must first unpack itself each time it is used.

    ReplyDelete