DEV Community

Discussion on: What JS Logging library / tool do you use?

Collapse
 
download profile image
Stijn de Witt • Edited

Please, please try ulog It is just over 1KB and it supports all this stuff out of the box. Plus it has a test suite and everything and does not have the bugs your home-brew implementation will have. I am speaking from experience. I have been developing this simple lib for years now and it is amazing how many things can (and will) go wrong in different environments when it comes to logging.

Basically I am hearing you guys re-inventing the wheel :) ulog has a simple config mechanism via env vars or localStorage that does exactly what you mention here, plus a bit more. Check it out and let me know what you think.

About the no-op thing.... It is probably just minimal overhead, not no overhead. But really if the overhead of an empty function call is an issue in your code, better look very carefully at your code because that should never be an issue.

What could be an issue is if you do this:

log.info(veryExpensiveFunctionCall())

The veryExpensiveFunctionCall() will be performed and the result passed to the no-op method... So still slow.

In ulog we fix that like this:

if (log.level >= log.INFO) {
  log.info(veryExpensiveFunctionCall())
}

The level check makes sure we only call veryExpensiveFunctionCall() if it is really needed.