pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

Support lazy message evaluation #88

Closed mfursov closed 8 years ago

mfursov commented 8 years ago

A simple example could be:

import log from "loglevel"
log.debug(()=>JSON.stringify(value));

I belive this feature will make loglevel very efficient.

pimterry commented 8 years ago

This is an interesting idea, but isn't something the core of loglevel is ever going to do. Any logic that needs to run at log time necessitates clobbering all stacktraces. Reliably giving you simple working logic without breaking anything (including traces from your log messages) is one of the core features of the library.

Extensions like this are the perfect case for plugins though. Take a look at https://github.com/pimterry/loglevel#writing-plugins in the docs for a bit more background on why this can't really be built in, and how you can set up your own plugin to build that on top of loglevel anyway.

I'm going to close this since I'm not happy to put it into the core library. Do let me know if you end up writing and releasing a plugin though, and I'll happily add a reference to it in the README.