Sunday, November 19, 2006

Client Side Logging

Server-side logging is pretty much old news - whether it's log4net, NLog or the .Net trace - you wont see an application without a logging framework\utility.

But while developing Web applications, most of our code will be executed on the browser, so no matter how strong our logging utility is, it wont cover a hole bunch of our code.

There are many solutions for this problem, and I'll cover 2 of my favorite.

Log4JavaScript
Log4JS's main goal is to have identical code for logging whether it's on your client side or - server side.
In order to do so, Log4JS implements almost fully the Log4J API.
For example:
In order to obtain a logger object, I request one from my repository:

var log = log4javascript.getLogger();


Then I configure my desired appender:

var popUpAppender = new log4javascript.PopUpAppender();
popUpAppender.setNewestMessageAtTop(true);
log.addAppender(popUpAppender);


And finally write to the log:
log.debug("Hello world!");


Pretty neat if you ask me ;)

JSLog
JSlog is a lot simpler and less customizable than the Log4JS but it still gets the job done and is very pretty ;)

There are many other client-side logging utilities but basically they're all the same.
But the question still stands - is client-side logging useful???

No comments: