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

VIEW FULL DISCUSSION
 

Before I proceed I must warn you I am the author of the logging library I am using, so there is a tiny possibility that I might be biased. Very tiny :)

ulog - The microscopically small universal logger

Basically ulog is debug meets loglevel meets the console. It works in Node JS and all major browsers (even old ones!)

  • Mostly works exactly like the console does
  • Supports levels that map to console methods (info, warn, error...)
  • Supports configuration of log level via query string/localStorage (browser) or environment variables (Node)
  • Supports a debug mode that selectively enables loggers
  • Smart default log levels

Why I built it

It started out because using console directly is basically VERBOTEN. Because some browsers simply don't support it and will crash your code. Also you need to remove these statements afterwards etc. Making logging difficult and error prone. So it started as a tiny shim that just makes sure that your code never crashes or fails whether console is available or not.

I then decided I wanted log level support so I added that. And then I discovered debug, which is GREAT, and I decided to copy those features I loved about that.

Why I think it is one of the best loggers

  • It is SMALL. Some loggers really go overboard but I need this stuff to be tiny. 1K is about all I want to spend on a logging lib
  • It supports levels. Levels make logging useful!
  • It has AWESOME debug features. Just set DEBUG=module1,module2 and these modules will start logging debug info
  • By default, only Error and Warning message will show up in the console in browsers, meaning you can log as much as you want and only those people that are interested in it will actually see it. You can just leave your log statements in your production code. In Node JS we use INFO as the default level because there the 'users' are mostly developers / server admins etc who are more interested in our logging. Using different defaults on different platforms felt weird at first but it actually works out great for my projects.
  • It supports a shorthand form that applies formatting.

Example usage

var ulog = require('ulog')
var log = ulog('my-module')

log.debug('Debug message');
log.info('Info message');
log.warn('Warning message');
log('Formatted message (at debug level)')
log('warn', 'Formatted message (at warning level)')

Yields (on browsers)

Warning message
21:23:24   .03 my-module                Formatted message (at warning level)

If you want to try it

Now is the perfect time as I am trying to perfect v2 currently. So if you want to try this, please install the beta and let me know:

npm install --save ulog@beta

Or you can use v1, but that version is more limited in features:

npm install --save ulog
code of conduct - report abuse