I'm the author of log4javascript and I use it every day in my work. Here's how I use it:
- I tend to use
debug()
and trace()
most frequently. I use trace()
for logging low level operations when trying to hunt down a bug and debug()
for more general logging of program flow. I have the console threshold set to DEBUG
for my usual coding so that I don't have trace messages cluttering up the log and then switch it to ALL
when I need to see the trace messages.
- I use
info()
quite a bit, usually to make particular messages stand out a little in the logging console.
- I make liberal use of
group()
(see http://log4javascript.org/docs/manual.html#loggers) to group logging for a particular operation and allows me to expand and collapse chunks of logging. Groups can also be nested.
- I keep my logging initialization code in one place and give each component of my application a separate logger (which inherits from the root logger). This allows me to set logging thresholds for particular components.
For example:
var component1 = (function() {
var log = log4javascript.getLogger("MyApp.Components.Component1");
// Implementation stuff
})();
var component2 = (function() {
var log = log4javascript.getLogger("MyApp.Components.Component2");
// Implementation stuff
})();
In the logging initialization code:
// Create a console appender that is inherited by all loggers
var appender = new log4javascript.PopUpAppender();
appender.setThreshold(log4javascript.Level.DEBUG);
// Limit the number of messages displayed in the console at any one time
appender.setMaxMessages(2000);
log4javascript.getRootLogger().addAppender(appender);
// Disable all logging except ERROR and FATAL for the "MyApp.Components"
// logger and all its descendants (including "MyApp.Components.Component1" and
// "MyApp.Components.Component2")
log4javascript.getLogger("MyApp.Components").setLevel(log4javascript.Level.ERROR);
This stuff is common to all log4x logging frameworks, so documentation from log4j or log4net will apply. For example, the old but still relevant log4j short manual may help.