module Hsm.Core.Log ( withLogIO , logTup , flushLogger ) where import Data.Aeson.Types (emptyObject) import Data.Text (Text) import Data.Time.Clock (getCurrentTime) import Effectful (Eff, (:>)) import Effectful.Dispatch.Static (unsafeEff_) import Effectful.Log qualified as L -- Helper function allows logging within IO, Useful during `resourcet` -- allocation and release operations. withLogIO :: L.Log :> es => Eff es (L.LogLevel -> Text -> IO ()) withLogIO = do logIO <- L.getLoggerIO return $ \level message -> do now <- getCurrentTime logIO now level message emptyObject logTup :: L.Log :> es => (L.LogLevel, Text) -> Eff es () logTup (level, message) = L.logMessage level message emptyObject flushLogger :: L.Log :> es => Eff es () flushLogger = L.getLoggerEnv >>= unsafeEff_ . L.waitForLogger . L.leLogger