Archive for the 'Javascript' Category

Presenting ring_logger v0.1

Monday, February 25th, 2008

 Ring logger

This weekend, I had an urge to catch up on one of the umpteen projects that I’d like to start, so I attacked a ring logger.

Basically, a ring logger, keeps the log messages in a ring buffer, which can be dumped when interesting circumstances arrise.

The particularité of this one is that it’s pure javascript, and dumps as a ‘POST’ request to a url. This allows for much improved debugging of js-rich web pages, whilst not filling up the web browsers memory with useless logs.

It depends on ToutouJS but doesn’t have a lot of calls, so it should be easilly portable if anyone finds the need.

 Usage

First off, you have to include the relevent files:

<script src="js/toutou/toutou.js" type="text/javascript"></script>
<script src="ring_log.js" type="text/javascript"></script>

Then you just log away (the mores the better):

js.ring_log.log(js.ring_log.DEBUG,'Test','Test message');

Finally, to retrieve your log, ie dump the buffer:

js.ring_log.dump();

Et voila!

For testing purposes, the logger is pre-configured to call a script log.php in the same directory as it is in, and has a buffer size of 10, both parameters changeable in the source. The different parts of the log messages are seperated by a ’splitter’, by default ‘==|==’, this is also configurable.

js.ring_log.requestUri='log.php';
js.ring_log.log_data_size=10;
js.ring_log.splitter='==|==';

And that’s just about it, hope you find it usefull :)

Update: forgot to add the .tgz, oups :$