Skip to content
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

Generalize filterLogger? #58

Open
mgsloan opened this issue Mar 24, 2015 · 1 comment
Open

Generalize filterLogger? #58

mgsloan opened this issue Mar 24, 2015 · 1 comment

Comments

@mgsloan
Copy link

mgsloan commented Mar 24, 2015

Currently, filterLogger :: (LogSource -> LogLevel -> Bool) -> LoggingT m a -> LoggingT m a. I'd like filterLogger :: MonadLogger m => (LogSource -> LogLevel -> Bool) -> m a -> m a.

Unfortunately, I can't see a way to do this without a breaking API change or a new typeclass.

Why do I want this? I have a function that's polymorphic on MonadLogger m, which invokes a library which has lots of log output. I'd like to silence some invocations of this library, but not others. I can do one of the following things:

  • Make LoggingT explicit in the type, losing polymorphism, and causing me to plumb this decision all the way through all the callers.
  • Create a new typeclass specifically for modifying the logger function.

The new typeclass could look something like this:

class LoggerLens m where
    loggerLens :: Lens' (m a) ((Loc -> LogSource -> LogLevel -> msg -> m ()) -> m a)

type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s

This would then allow polymorphic implementations of filterLogger and withChannelLogger. NoLoggingT would get an improper lens, but I think that's ok.

Personally, I'd prefer that this capability always be available to MonadLogger instances, but I realize the API breakage would be huge.

Thoughts? Maybe something like this can make it into the next major-major release?

@mgsloan mgsloan changed the title Generalize filterLogger? Generalize filterLogger? Mar 24, 2015
@snoyberg
Copy link
Collaborator

If we're going for majorly breaking changes, I think we have better options at our disposal, specifically to model this as a MonadReader, together with a local method. The downside is that we either need to explicitly state the base monad (IO) or use a type family/fundep to establish it. Still, that feels much less ad-hoc than using a lens like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants