News for hackers. Stuff that matters.
Re:Why a Logging Framework Should Not Log by setheron on Thursday May 05, 2016 @12:26PM (#11637491)
This is a well understood problem and I think the design pattern SLF4J uses has become quite popular.

The ability to allow consumers to bind at runtime the implementation they want by providing an api jar is kind of a neat idea.

The thing I dislike the most is when libraries force me to use their logging runtime. If they need it just for tests they should add the 'test' scope and just use the 'api' jar as a 'compile' dependency.

Re:Why a Logging Framework Should Not Log by btilly on Thursday May 05, 2016 @01:22PM (#11638023)
It has become popular, but it is still wrong. If you're a nested dependency, then DON'T require end developers to be aware that you're there. Doing so makes you a leaky abstraction.

http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...

Though the author does have a point that fault here could be put on the library that added the dependency without a default logging behavior. However I'd still blame SLF4J for making the default case suboptimal.

Re:Why a Logging Framework Should Not Log by emodendroket on Thursday May 05, 2016 @01:53PM (#11638282)
But it seems useful because you can decide what behavior your want for your project.
Re:Why a Logging Framework Should Not Log by btilly on Thursday May 05, 2016 @01:59PM (#11638341)
Right, it is configurable.

But there is no reason why a configurable library can't have reasonable default behavior if no configuration is supplied. While still being configurable. If you're winding up as a buried dependency that end developers may not be aware of or care about, you want to do this.

Re:Why a Logging Framework Should Not Log by vertex-four on Thursday May 05, 2016 @02:38PM (#11638681)
What reasonable default behaviour? If you're writing a console application, dumping to stderr is probably not a good idea - writing random log files that the end-user/admin has no idea about is probably not a good idea - shutting up and doing nothing is probably not a good idea (Java code has a tendency to use logging to warn about non-fatal configuration errors, etc). And let's not get started on what verbosity to set by default.
Re:Why a Logging Framework Should Not Log by btilly on Thursday May 05, 2016 @03:21PM (#11638979)
A good default is to write to STDERR if the severity level is above some threshold, otherwise do nothing.

That way the console can tell you about configuration errors, and by default the library will log nothing. If the library author considers it important to log somewhere, the library author is responsible for putting both an understandable warning up, and writing documentation.

Re:Why a Logging Framework Should Not Log by marcosdumay on Thursday May 05, 2016 @05:25PM (#11639776)
If you are creating a library? You shouldn't log at all. Return errors or throw them - do not log.

If you are creating a console application? Stderr is the standard way to log errors. Let the user decide if where it points to.

If you are creating a daemon, set the log destiny at the launch script. The application can either log to stderr anyway and let the script handle everything, or offer a parameter for setting the log channel.

The Java community fixation on logging is really not deserved. It's more caused by bad error handling by their main web servers than by any fundamental problem.

Re:Why a Logging Framework Should Not Log by empthought on Thursday May 05, 2016 @07:18PM (#11640449)
Logging is useful for more than just error conditions; how does that square with your advice to library authors?
Re:Why a Logging Framework Should Not Log by marcosdumay on Thursday May 05, 2016 @08:23PM (#11640772)
If it's not an error condition, you return it.

Libraries must not do any covert IO (in fact, any covert anything). A logging library is the only one that should log, and not their own messages.

They may write into some main application supplied collector, if it is not global, or if it is clearly handled as a message passing API.

The Java way is simply bad.

Re:Why a Logging Framework Should Not Log by empthought on Friday May 06, 2016 @08:37AM (#11643511)
Maybe I'm misunderstanding your point -- by "do not log," do you mean do not call logging statements in a logging library's API, or simply do not force a concrete implementation of a logging library? I understand and agree with the second one completely, but the first one seems unrealistic.

I can't see how the Apache httpclient library could sanely "return" the different state transitions and pieces of data that are logged in its wire-level logging, but this is certainly a case where the logging statements are welcome.

Re:Why a Logging Framework Should Not Log by marcosdumay on Friday May 06, 2016 @01:33PM (#11645413)
Yes, if you created a framework, that will call your code, yes, it can log. It can also provide a logger implementation, or request one from you, whatever it deems better, and your code must comply.

But a library, that your code will call, must not log. Ever. That includes any portion of a framework that you have to call, but it using services upper on the stack can make this rule hard to see. It must not include a logger implementation, and not call any global logger supplied from you.

It seems we are arguing over the definition of those two cases.

Re:Why a Logging Framework Should Not Log by empthought on Friday May 06, 2016 @01:45PM (#11645485)
So in the case of Apache HTTPClient (which I would call a library), are you saying that it is a design flaw that it provides logging statements of its internals, when provided the proper configuration/logging implementation?

If so, I would have to disagree based on pragmatic grounds, unless you have another credible way to acquire the information present in http wire logging or connection pool events, for example.

Re:Why a Logging Framework Should Not Log by emodendroket on Thursday May 05, 2016 @02:18PM (#11638520)
True enough. I guess the main downside would be including a library that may never be used.
Re:Why a Logging Framework Should Not Log by phillord on Thursday May 05, 2016 @01:52PM (#11638275)
It doesn't force anything though, unless you statically refer to the runtime. It does force you to exclude their logging backend, but that is straight-forward enough.
Re:Why a Logging Framework Should Not Log by theanomaly on Thursday May 05, 2016 @01:59PM (#11638349)
Yes, but you have to know to exclude their backend. And, that library may be several dependencies deep. Now you're expecting potentially junior developers to have the insight to grep their entire transitive dependency tree, find the nop dep, and exclude it. This kind of silent failure is worse than the alternative.
Re:Why a Logging Framework Should Not Log by duaneb on Thursday May 05, 2016 @02:27PM (#11638582)
Dependency exclusions is a code smell everywhere but java. I don't understand why someone is actively giving this advice.
Re:Why a Logging Framework Should Not Log by phillord2 on Thursday May 05, 2016 @03:33PM (#11639057)
The alternative is not specifying a nop dependencies and then inflicting on downstream uses the choice that I was not prepared to make.