Discuss: JavaScript Logging
by David F. Miller
- Editorial Comments
22 And for the keyboard users
I believe it would be beneficial to add onkeypress=�showInfo();“ to those links, for keyboard users.
posted at 02:48 am on September 10, 2005 by Mike Cherim
23 Interactive Debugging in IE
IE has a JavaScript debugger too. Visual Interdev & VS.NET can be used for interactive JavaScript debugging in IE at about the same level of functionality as Venkman. There are a few options you have to enable in IE to turn on script debugging.
Logging is powerful for tracking down problems you didn’t expect to happen, assuming logging is occuring in the right places and there’s a way to get at the log output. A nice feature for fvlogger would be “crash report” submission UI so users could report failures back to the site maintainer.
When you know a problem exists interactive debuggers are often more efficient than trial-and-error logging, and are worth the effort spent learning thier quirks. Plus, you get to skip the frustrating “trial-and-error” step.
posted at 02:38 pm on September 10, 2005 by Wade Dorrell
24 Untitled
This is very nice.
A couple of features I would add:
1) Date/Timestamps prefixing each log, – auto generated.
2) A global switch to turn logging on and off.
All up, – very sweet! Nice article.
- James
posted at 06:29 am on September 12, 2005 by James Head
25 For the record, another logging mechanism
This logging script looks very nice and I’m certainly going to give it a try. If it’s of any use to anyone, there is another logging mechanism I have been using for several years. This is IE only, and only of use for debugging scripts running on your local box. Despite these limitations, if that’s the setup you are debugging, it is quite powerful. This is an activex dll, originally made available by Microsoft in the IIS 4 resource kit, called IISSamples.Tracer. It is a very light c++ wrapper round the printDebugString windows api call. All messages logged via this utility can be viewed in the (free) debugviewer utility from sysinternals. The main advantage of this mechanism is that the logging is very fast, particularly useful when debugging mousemovements etc where the overhead of javascript logging methods may interfere with the script you’re trying to debug. It also prints accurate timings with the messages. I don’t beleive this is available on the web anymore, and I have no means of posting it but if you want a copy, email me and I’ll send it to you.
posted at 08:15 am on September 12, 2005 by steve heron
26
James,
Thanks for your comments; you can turn logging on/off by setting the value of FVL_LOG_ON to false in logger.js. As for the timestamping of logging statements, I’ll definitely consider it for a future version, although it’s relatively simple to implement if you’re familiar with JavaScript. If you need a hand, let me know. Cheers!
Dave
posted at 01:59 pm on September 12, 2005 by David F. Miller
27 script element
Someone was wondering if this is correct:
[removed]
They were correct, script is not an empty element in the (X)HTML DTD, so must be written as:
[removed][removed]
posted at 09:32 pm on September 18, 2005 by Michael Newton
28 writing log to a file
Great article.
I think that you could also use this technique to write out javascript errors to a logfile on the server. This would be a handy way to catch user-generated js errors in production. Instead of writing the errors to a document object, write them to a variable, and then pass that variable using XMLHttpRequest to a server-side script which then captures the message to a file. Only problem I can think of is that this script is then exposed to the public, and someone mischievous could write tons of messages to your server. But perhaps this would be something you would deploy only on a case-by-case basis when you want to track down elusive, idiosyncratic bugs.
posted at 12:59 am on September 19, 2005 by Dale Lum
29 Another JS logger (shameless plug)
I enjoyed looking at your take on the javascript logger. If you are looking for something that acts more like Log4J, I wrote a quick logging class for some of my own projects called log4js – http://log4js.sf.net . It is a little more robust in that it allows for multiple loggers per page (each is an object), and multiple targets, such as alerts, a popup dialog, or the safari javascript console…
Then again, it is written by a java programmer returning to javascript after a long hiatus.
posted at 02:45 am on September 20, 2005 by Marcus Breese
30 I like it
Nice stuff. I have already started using it and find it quite useful.
ALA, Keep such article coming. ALA has saved me so much time with such high class material.
Thanks for the Good stuff,
Venkat.
posted at 07:45 am on September 21, 2005 by Venkat Kalyanaraman
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?)






21 Sample has a minor bug
At about line 43 of the index.html example, the line needs to be changed to:
<dd class=“info”>[url=”#fvlogger” ]info[/url]</dd>
The line needs the onclick to show the Info blocks.
Thanks for a great little tool.
posted at 12:57 pm on September 9, 2005 by Foster S