Download / ulog

The universal logger
https://ulog.js.org
MIT License
88 stars 19 forks source link

Remove dependency on anylogger #64

Closed xmedeko closed 3 years ago

xmedeko commented 3 years ago

From README.md https://github.com/Download/ulog#use:

npm install --save anylogger && npm install --save-dev ulog

However, when I want to use ulog without anylogger:

 npm install --save ulog

then the anylogger is installed anyway because it's in the packages.json as dependencies. The logger should be independent to logging facade. (IMO logging facade is great for lib development, but I do not find it useful for the app development.)

Download commented 3 years ago

I disagree. Whether you are developing an app or a lib, there is no reason to make your dependencies more specific than needed. For 99.9% of logging code, all you need is the anylogger API. I explicitly recommend against writing

const ulog = require('ulog')
const log = ulog('my:logger')
log.info('logging is easy, but this is more specific than needed')

Instead, write

const anylogger = require('anylogger')
const log = anylogger('my:logger')
log.info('logging is easy, especially if you keep it generic')

Both code fragments do effectively exactly the same thing when using ulog, but the second code fragment you can change the underlying logging framework to loglevel or debug or any other logging framework for which an anylogger adapter exist, by just installing a different adapter and changing a single line in your entry point. That flexibility is valuable. And in my experience, most libs start out as part of apps.

The point of a facade is to hide the underlying system. That's why I recommend always talking to the facade whenever it's possible.

Anyway, I you were to remove anylogger, ulog in it's current for would not work. I carefully wrote anylogger to make it possible to re-use as much code from it as possible and ulog does just that. If I would try to remove anylogger, I would end up having to copy a large part of anylogger to ulog, and people would need an adapter to use ulog with anylogger. Yes, it's a dependecy, but even with that dependency ulog's footprint is still only 2.7kB.

when I want to use ulog without anylogger

Can you explain why you want this?

xmedeko commented 3 years ago

I've been working with quite a few loggers in various programming languages and this approach is unusual. IMHO logging facade is needles for the app development. You very rarely need to switch logging lib and if so, it may be tedious but not impossible (usually much simpler than e.g. to switch SQL database.). So, IMO the logging facade just brings unnecessary complexity for the app development.

Anyway, you are right the ulog and anyloger API is same and footprint is small. So, it's not a blocker in using ulog. Treat this issue just as an advice and not a requirement.

Download commented 3 years ago

Thanks. If you want, you can still write your code directly to ulog of course. But technically to get rid of the dependency from ulog on anylogger would be just not sensible I think. I hope you are ok if I close this. Feel free to comment and request re-open if not.