Discuss: JavaScript Logging
by David F. Miller
- Editorial Comments
12 Another JavaScript trace utility
I’m always had a hard time debugging JavaScript. The Venkman debugger is too unwieldy most of the time. I’ll add this to my list of tools.
I wrote a similar utility a few weeks ago. It’s quick and dirty. It does not have multiple error levels, although that could be added. If anyone is interested, it’s here: http://www.connectedpixel.com/blog/javascript/trace
posted at 06:12 pm on September 6, 2005 by Joel May
13
I’m glad the article is being well-received; I’ve been using the code in several projects myself and have found it to be a pretty invaluable tool. Keep the thoughts/comments/improvements/suggestions/etc. coming; the more topics such as this one are discussed the better we will all be for it.
As for the code itself… Yeah, there are a few different ways to deal with browsers and how they handle attributes and their values. Looping through the list of attributes and doing an exhaustive name comparison is by no means the most efficient (or elegant) method of finding the class name, but it does get the job done. Like most topics related to scripting browsers, it’s a matter of finding a balance between what works in every browser, what should work in every browser, and maintaining your sanity while cobbling together whatever hack you can come up with.
posted at 06:43 pm on September 6, 2005 by David F. Miller
14
Ted,
The values of all the node’s attributes are being echoed to the debug log merely to illustrate the difference between how Internet Explorer and every other browser handles node attributes. Sorry for the confusion.
posted at 06:47 pm on September 6, 2005 by David F. Miller
15 Safari...
Safari also has a javascript debugger. You need to enable the Debug menu in safari, which can be done by typing the following into terminal (make sure safari is closed):
% defaults write com.apple.Safari IncludeDebugMenu 1Then relaunch safari, and from the debug menu you can open a js console.
posted at 10:28 pm on September 6, 2005 by Eric Coleman
16 Light-debugging
I myself tend to create an extra DIV on the page, style it with position:absolute; and fill its innerHTML with various debugging values. It’s a step up from the alert() in that it does not halt the script (allowing time-bugs to expose themselves) and does not require lots of clicks in case your bug is inside a loop.
The downside is of course the numerous bugbox[removed] = ‘such and such’; spread across the script, which need cleaning up after bugs have been zapped.
It’s always served me well, but maybe I’ll try ouy fvlogger. See if the glove fits.
Safari also has a javascript debugger. You need to enable the Debug menu in safari
I think that should be a default, instead of a carefully hidden option. But then again, the JS engine of Safari does not behave strangely compared to the Gecko engine, at least not for my scripts. A Bbg fixed in Gecko equals a bug fixed in Safari.
posted at 07:12 am on September 7, 2005 by Willem Jeffery
17
Yes, Safari and Firefox both include excellent JavaScript debuggers, but they only provide debugging information for that particular browser. To find out what your script is doing in another browser (typically IE), then the information gleaned from that debugger may or may not be totally useless.
posted at 06:56 pm on September 7, 2005 by David F. Miller
18 Self-closing <script> tags and IE
The article instructs us to use the following self-closing script tag to load the JavaScript source code:
[removed]
However, in my experience, Internet Explorer does not seem to “like” self-closing script tags and fails to load the script. Can anyone else confirm this or provide any additional information on the topic?
On a side note, if you look at the actual source code of the article, you’ll notice that they don’t follow their own advice and instead use:
[removed][removed]
Perhaps the article example should be corrected to use a closing script tag.
posted at 02:41 pm on September 8, 2005 by Richard Davies
19 Who will do the popup window hack?
first off, this makes me so happy. Stupidly simple and brilliant. Secondly, I hope someone will beat me to it (as I am a Javascript hack, but I will take a stab this weekend at implementing this as a popup window.
posted at 04:10 pm on September 8, 2005 by Josh Brandt
20 Other loggers
You might want to give Lumberjack a try. It seems less complicated to use than fvlogger (But it only has been tested to work with Firefox 1.0+ and IE 6.0+) It also has a real nice demo page
posted at 11:09 pm on September 8, 2005 by Corey Johnson
Discussion Closed
New comments are not being accepted, but you are welcome to explore what people said before we closed the door.
Got something to say?
Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.
Create a new account or sign in below if you’d like to leave a comment.
Subscribe to this article's comments: RSS (what’s this?)






11 What do you do with all of the IE attributes
I’m a bit confused.
You cure the class element on IE, but when I looked at the logging, I still see the 84 attributes. I’m still learning javascript and would have trouble figuring out what is worth worrying about in those 84 attributes. Are they a problem? Is the logging example above the fix using the fix?
posted at 05:01 pm on September 6, 2005 by Ted Drake