Monday, September 12th, 2005

Logging in JavaScript with fvlogger

Category: Articles

David Miller has written a lovely article on JavaScript logging.

He takes us on the ride that we took when running from alert(), and onto browser tools such as Venkman for Mozilla.

Finally he gets to fvlogger, his logging toolkit for JavaScript.

fvlogger borrows concepts from Log4J and its cousins, but eschews their complexity by providing a simple API and offloading the heavy lifting onto the DOM.

The library defines four basic functions (and provides a few others that can be considered optional), a few flags that can be set to define its behaviour, and several CSS classes that can be used to govern how the log will appear. It requires just one special element to be placed in the document, and including fvlogger in your pages is as easy as adding the following two lines to the head of your documents:

<script type="text/javascript" src="/fvlogger/logger.js" />
<link rel="stylesheet" type="text/css" href="/fvlogger/logger.css" />

Essentially, all fvlogger does is append new elements to a specific element in the document. These new elements contain the logging messages that will assist you in debugging your script(s). The four functions used to create the log messages are: debug(msg), info(msg), warn(msg), and error(msg). Each function expects a single string that will be appended to the document.

And then he shows an IE quirk via logging itself!


Posted by Dion Almaer at 1:13 am

3 rating from 5 votes


Comments feed

Unfortunately the programming style of the script makes it look like a fossil from the 1990s. Everything is defined at top-level, polluting the global scope with lots of rather generic names where the danger of a clash with other scripts is considerable. Taking into account the high-profile presentation in ALA, and the resulting wide circulation of the script, better care should have been taken of the programming style.

Comment by Michael Schuerig — September 12, 2005

While fvlogger is cool, it doesn’t hold a candle to Lumberjack

Comment by Richard — September 12, 2005

Leave a comment

You must be logged in to post a comment.