Logging from a 3rd party library


I’m going to write a library, I doubt it’ll be used by many, but still for the sake of my peace of mind and maybe learning a bit I was wondering if there’s any smart way of having a dynamic logger, where the user of the library can pick which one.

My thinking is that there are a fair amount of loggers in the wild, and lots of opinions on which one is best. Library logs can be very important in debugging and postmortems, but say you have a setup where you log in JSON to STDOUT with specific fields, then use logstash to be able to view things in kibana library x spewing out things in either plain text or JSON where you have no control over the fields, those logs disappear or at least become very cumbersome to find. Could just as well be that logs should go to STDERR, a specific file etc.

So, is there any sane way of handling that? The hard typing makes it kind of tricky. Having some local interface which have the usual suspects of logging function like this https://play.golang.org/p/c9VuOOnq_dM is what I can come up with spontaneously, but hopefully have someone else thought a bit about this.

So, the question is: Any good ideas regarding logging from libraries?

Should I rephrase my question or is this the wrong forum?

Is this your question?

In short yes, I see plenty of libraries rolling their own loggers and was hoping someone had a good implementation to avoid that. So that the library logs can be in the same format as the client, and going to the same file.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.