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:
my-library.js
varanylogger=require('anylogger')varlog=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:
This installs my-library, anylogger, debug and the anylogger-debug adapter.
Then, in your main.js, just require the adapter and it will work:
main.js
require('anylogger-debug')vardebug=require('debug')debug.enable('my-library')// 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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 installanylogger
like this:Then in your code, you would create and use a logger like this:
my-library.js
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 installmy-library
into your application project and make it usedebug
:This installs
my-library
,anylogger
,debug
and theanylogger-debug
adapter.Then, in your main.js, just require the adapter and it will work:
main.js
I am working towards an 1.0 release and would appreciate feedback.