12/17/2025 at 9:56:26 PM
Libraries shouldn't log. Just have your top-level abstractions extend an EventEmitter base, emit appropriate events, and let the user do the rest.by tengbretson
12/17/2025 at 11:48:41 PM
This is so simple and makes so much sense. I’ve seen a couple libraries that do something similar, but I feel like this is obvious and useful enough that it should just be a stock pattern, and it clearly isn’t.by roblh
12/17/2025 at 10:00:33 PM
Why shouldn’t libraries log?by ivan_gammel
12/17/2025 at 11:16:23 PM
Aside from what some other users have said, logging is fundamentally an observable side-effect of your library. It’s now a behavior that can become load-bearing — and putting it in library code forces this exposed behavior on the consumer.As a developer, this gets frustrating. I want to present a clean and coherent output to my callers, and poorly-authored libraries ruin that — especially if they offer no mechanism to disable it.
It’s also just _sloppy_ in many cases. Well-designed library code often shouldn’t even need to log in the first place because it should clearly articulate each units side-effects; the composition of which should become clear to understand. Sadly, “design” has become a lost art in modern software development.
by bitwizeshift
12/18/2025 at 9:42:47 PM
In Java world logging in libraries is effectively a no-op unless explicitly enabled by user, so side effects are negligible. And it actually does make sense, e.g. when a library is offering a convenient abstraction level over i/o, parsing or other stuff with initially unknown failure modes, where some logs may help clarifying the picture beyond handling an exception or error code. The way logging is done there is the art of good software design, which has never been lost (it may have not reached other platforms though). So I disagree with you and some other commenters: strict Verbot is dogmatic, and good design is never dogmatic.by ivan_gammel
12/17/2025 at 10:15:57 PM
It depends a lot on the language, but in my field libraries that have their own logging implementation and that don't provide hooks to override it cause big problems for me because I send all the logs to the same central logging client that forwards it to the same central logging server for aggregation. Your logging probably dumps it to a file, or it writes it to STDOUT, or something similar, in which case now I have to pipe all of that data in two places by doing something hacky.There are some language ecosystems that have good logging systems like Java which I would be totally fine with. But systems languages like C/C++ that don't have a core concept of a "log message" are a pain to deal with when the library author decides to stream some text message somewhere. Which is probably a good argument for not using those languages in some circles, but sometimes you have to use what you have.
So it's not really a blanket "don't do it" but you should carefully consider whether there's some well-known mechanism for application authors to intake and manage your logging output, and if that doesn't exist you should provide some hooks or consider not logging at all except with some control.
by throwway120385
12/18/2025 at 1:07:26 AM
It tends to break composability.The behavior of the library logging can be incompatible with the architectural requirements of the application in dimensions that are independent of the library functionality. It requires the user to understand the details of the library's logging implementation. Even if documented, design choices for the logging will automatically disqualify the library for some applications and use cases.
Is writing the log a blocking call? Does it allocate? Synchronous or async? What is the impact on tail latencies? How does it interact with concurrency? Etc.
by jandrewrogers
12/17/2025 at 10:06:27 PM
Because they have to be compatible with your logging implementation, and they were written first.by mrkeen
12/17/2025 at 10:16:15 PM
Any log produced directly by a library will just be a "what" detached from any semblance of a "why".by tengbretson
12/17/2025 at 10:14:03 PM
Because libraries don't know where or even how the user wants it to log.by charcircuit
12/17/2025 at 11:25:14 PM
That's why a library (if it absolutely must do logging) should always allow the user to optionally inject their own logger implementation.by Hackbraten
12/18/2025 at 9:38:37 AM
Isn't that basically what the average logging framework is?by rcxdude