module Polysemy.Log.Handle where
import qualified Data.Text.IO as Text
import System.IO (BufferMode (LineBuffering), Handle, hSetBuffering)
import Polysemy.Log.Data.DataLog (DataLog)
import Polysemy.Log.Log (interpretDataLog)
interpretDataLogHandleWith ::
Member (Embed IO) r =>
Handle ->
(a -> Text) ->
InterpreterFor (DataLog a) r
interpretDataLogHandleWith :: forall (r :: EffectRow) a.
Member (Embed IO) r =>
Handle -> (a -> Text) -> InterpreterFor (DataLog a) r
interpretDataLogHandleWith Handle
handle a -> Text
fmt Sem (DataLog a : r) a
sem = do
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed @IO (Handle -> BufferMode -> IO ()
hSetBuffering Handle
handle BufferMode
LineBuffering)
(a -> Sem r ()) -> InterpreterFor (DataLog a) r
forall a (r :: EffectRow).
(a -> Sem r ()) -> InterpreterFor (DataLog a) r
interpretDataLog (IO () -> Sem r ()
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed (IO () -> Sem r ()) -> (a -> IO ()) -> a -> Sem r ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Text -> IO ()
Text.hPutStrLn Handle
handle (Text -> IO ()) -> (a -> Text) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
fmt) Sem (DataLog a : r) a
sem
{-# inline interpretDataLogHandleWith #-}