[OpenLayers-Dev] Integrate simple logging framework in 3.0?
Gregers Gram Rygg
gregersrygg at gmail.com
Fri Jun 18 08:16:32 EDT 2010
Hi,
In the constructor signatures thread I brought up the need for a
logging framework. What do others think?
To throw Errors is quite useless from a minified library, since the
file name and line number is not related to a human readable source.
I've started to wrap my classes with a function to get a private
scope. Then I can have a "private static" log object for the class:
SMap.Layer.Pois = (function(){
var superObj = OpenLayers.Layer
,log = Logger.getLogger('SMap.Layer.Pois');
return OpenLayers.Class(superObj, {...});
}());
To use a private scope is another discussion. The log object could
easily just be a property on the prototype instead.
The log framework returns an object with log, debug, info, warn and
error methods. So I can easily log from anywhere in the class:
log.error("Constructor argument options require property: " +
this.requiredOptions[i]);
Which clearly show an error with the class name in Firebug, IE8,
Opera, Safari and Chrome.
Default turned off for production environments. To debug:
Logger.modules = {
'*': 'WARN',
'SMap.Layer.Pois': 'DEBUG'
};
Or dynamically during runtime:
initialize: function() {
Logger.modules['SMap.Layer.Pois'] = "DEBUG";
...
}
I suppose there are better logging frameworks out in there, but we
will gladly donate ours if there is an interest. See full source here:
http://kart.finn.no/rel/head/js/external/logger/Logger.js
What are others using? log4js?
Is it a de facto standard log library for JavaScript, like log4j in Java?
Best regards,
Gregers
More information about the Dev
mailing list