Skip to content

Instantly share code, notes, and snippets.

@int-index
Last active December 14, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int-index/fca78d931e59bdd9688054d132d4a241 to your computer and use it in GitHub Desktop.
Save int-index/fca78d931e59bdd9688054d132d4a241 to your computer and use it in GitHub Desktop.
Logging not disabled
{-# LANGUAGE GeneralizedNewtypeDeriving, FlexibleInstances, OverloadedStrings, UndecidableInstances #-}
import Control.Monad.Logger
import Control.Monad.Trans
import Control.Monad.Trans.Identity
import Data.Coerce
class Monad m => MonadFoo m where
foo :: m ()
newtype FooT m a = FooT (IdentityT m a)
deriving (Functor, Applicative, Monad, MonadTrans, MonadLogger)
runFooT :: FooT m a -> m a
runFooT = coerce
instance MonadLogger m => MonadFoo (FooT m) where
foo = lift (logErrorN "Logging active")
instance {-# OVERLAPPABLE #-} (MonadFoo m, MonadTrans t, Monad (t m)) => MonadFoo (t m) where
foo = lift foo
main = runStdoutLoggingT $ runFooT $ do
logInfoN "Stdout logging, message displayed"
foo
runNoLoggingT $ do
logInfoN "No logging, this message not displayed"
foo
@int-index
Copy link
Author

ghci> :main
[Info] Stdout logging, message displayed
[Error] Logging active
[Error] Logging active

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment