I am using log4javascript to log and track the issues in my JavaScript code. I have seen similar logging aids before but I am having difficulty in understanding how each of these log levels should be used to be more useful and productive.
Most of the time I end up logging debug, info or trace without being really aware of how productive each of them are or not. As the code grows larger and larger it's getting tough and I feel logs are more trouble than help.
Can someone give me some guidelines/help so that I can use the logging mechanism well.
Following are the different log levels supported by the log4javascript:
log4javascript.Level.ALL
log4javascript.Level.TRACE
log4javascript.Level.DEBUG
log4javascript.Level.INFO
log4javascript.Level.WARN
log4javascript.Level.ERROR
log4javascript.Level.FATAL
Logging mechanisms enable developers to track potential errors in their applications – identify, locate, and get information about solving them.
I'm the author of log4javascript and I use it every day in my work. Here's how I use it:
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.info()
quite a bit, usually to make particular messages stand out a little in the logging console.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.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With