co-log-simple-1.1.0: src/lib/Colog/Simple.hs
{-|
This module is for creating 'LogAction' instances that use the logging and
formatting functions in this library.
@
import Colog.Monad (usingLoggerT)
import Colog.Simple (Severity (..), colorSevFmt, logger, logNotice, logTextStdout)
usingLoggerT (logger (sevc % msg) logTextStdout Debug) $ logNotice "Take note of this!"
@
The 'LogAction' produced by 'logger' above is what you would put in your
ReaderT environment as well. See co-log documentation for more info on
integrating with transformers.
<https://github.com/co-log/co-log/blob/main/tutorials/custom/Custom.md>
-}
module Colog.Simple
(
-- * Constructing LogAction loggers
logger
-- * Utility functions
, logTest
-- * Re-exported from co-log-simple
, module Colog.Simple.Message
, module Colog.Simple.Severity
-- * Re-exported from co-log
, HasLog (..)
, LogAction
, logTextStderr, logTextStdout
)
where
import Colog (LogAction)
import Colog.Actions (logTextStderr, logTextStdout)
import Colog.Message (formatWith)
import Colog.Monad (HasLog (..), WithLog)
import Control.Monad.Trans (MonadIO)
import Data.Text (Text)
import Colog.Simple.Message
import Colog.Simple.Severity
-- | Construct a logging action
logger :: MonadIO m
=> (Message -> Text) -- ^ Format function
-> LogAction m Text -- ^ Where log message output will go
-> Severity -- ^ The severity level to filter at or above
-> LogAction m Message
logger fmtFs targetAction sev' = setSeverity sev' . formatWith fmtFs $ targetAction
-- | Test function to generate messages with every severity in this library
logTest :: WithLog env Message m => m ()
logTest = do
logDebug "log test message Debug 1 of 5"
logInfo "log test message Info 2 of 5"
logNotice "log test message Notice 3 of 5"
logWarning "log test message Warning 4 of 5"
logError "log test message Error 5 of 5"