re: What JS Logging library / tool do you use? VIEW POST


For all you guys out there using the console directly, because you don't want to commit to some logging library, I came up with anylogger. It is a ~360 bytes minified and gzipped logging shim that wraps the console. But it is also a facade object that supports an adapter pattern to plug in support for the logging framework of choice.

For example, if you were building my-library, you could install anylogger like this:

npm install --save anylogger

Then in your code, you would create and use a logger like this:


var anylogger = require('anylogger')
var log = anylogger('my-library')
log('Logging is simple!')

This adds a tiny, ~360 bytes overhead to your library, but you now have configurable logging support. Suppose you discover you really like debug and want to use it in your new project that is using my-library. Here is how you would install my-library into your application project and make it use debug:

npm install --save my-library anylogger debug anylogger-debug

This installs my-library, anylogger, debug and the anylogger-debug adapter.

Then, in your main.js, just require the adapter and it will work:


var debug = require('debug')
// you should start to see logging from 'my-library'
// in the format expected from debug

I am working towards an 1.0 release and would appreciate feedback.

Code of Conduct Report abuse