-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withMinimalLevel feels wrong / doesn't work in slf4j #240
Comments
Oh, and An additional benefit of this redesign would be having a single place where level filtering is done - right now I can see it in I'm not sure how bad this will be for performance... but it shouldn't be too hard to implement and just see. |
Good catch. Need to think about it further. Original implementation had a |
#244 worked, can you make a release? :) |
Sure. 0.11.0 is on the way to maven |
Thanks! |
Hi!
I've noticed weird behavior: I was using the monoid logger to combine two loggers (
consoleLogger.withMinimalLevel(Info) |+| fileLogger(minLevel=Debug)
.I passed this to the sfl4j interop without changes, and to my surprise, I started seeing DEBUG logs in my console! When I removed the file logger, leaving just the console one, I only saw INFO and above in the console.
I believe the culprit is this: the slfj4 logger calls the underlying logger's
log
method:And so does the Monoid logger. When I used the monoid logger directly with methods like
.debug
, I wouldn't notice it, because it would call the underlyingdebug
methods:So the level-based filtering would apply, and everything would work well.
But because the sfl4j logger calls
log
directly, after only checking that the message fits the underlying logger level (which, in case of MonoidLogger, is the lowest one - Debug), all loggers that take part in a monoid composition will print the message, even if they are wrapped inwithMinimalLevel(max)
.I think this is wrong - and the culprit is probably in the design of
DefaultLogger
and thelog
signatures:This one never does any filtering.
This one does the filtering and, if the level matches the underlying logger, forwards to
def log(LoggerMessage)
.I think
DefaultLogger
should instead:log: LoggerMessage=>F[Unit]
parameter or an abstract class with an abstract method like thatdef trace[M](msg: => M, ctx: Map[String, String])(implicit render: Render[M], position: Position): F[Unit]
as plain forwarders to a still- abstractlog
method:log(Level.Trace, msg, ctx)
A new abstraction, like
MinLevelLogger
should be introduced. It would:log
) implementeddef log(LoggerMessage)
and do the filtering based on the argument's level - further forwarding tounderlying
orF.unit
.The text was updated successfully, but these errors were encountered: