| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Effects.Logger
Description
Provides logging effect and utilities..
Since: 0.1
Synopsis
- class Monad m => MonadLogger (m :: Type -> Type) where
- monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> m ()
- data LogLevel
- levelTrace :: LogLevel
- levelFatal :: LogLevel
- logTrace :: Q Exp
- logDebug :: Q Exp
- logInfo :: Q Exp
- logWarn :: Q Exp
- logError :: Q Exp
- logOther :: Text -> Q Exp
- logFatal :: Q Exp
- guardLevel :: Applicative f => LogLevel -> LogLevel -> f () -> f ()
- shouldLog :: LogLevel -> LogLevel -> Bool
- data LogFormatter = MkLogFormatter {
- locStrategy :: !LocStrategy
- newline :: !Bool
- threadLabel :: !Bool
- timezone :: !Bool
- defaultLogFormatter :: Loc -> LogFormatter
- data LocStrategy
- = LocPartial !Loc
- | LocStable !Loc
- | LocNone
- formatLog :: (HasCallStack, MonadThread m, MonadTime m, ToLogStr msg) => LogFormatter -> LogLevel -> msg -> m LogStr
- _LevelTrace :: Prism' LogLevel ()
- _LevelInfo :: Prism' LogLevel ()
- _LevelDebug :: Prism' LogLevel ()
- _LevelWarn :: Prism' LogLevel ()
- _LevelError :: Prism' LogLevel ()
- _LevelOther :: Prism' LogLevel Text
- _LevelFatal :: Prism' LogLevel ()
- data LogStr
- data Loc
Effect
class Monad m => MonadLogger (m :: Type -> Type) where Source #
A Monad which has the ability to log messages in some manner.
Minimal complete definition
Nothing
Methods
monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> m () Source #
default monadLoggerLog :: forall (m' :: Type -> Type) (t :: (Type -> Type) -> Type -> Type) msg. (MonadLogger m', MonadTrans t, MonadLogger (t m'), ToLogStr msg, m ~ t m') => Loc -> LogSource -> LogLevel -> msg -> m () Source #
Instances
Levels
Constructors
| LevelDebug | |
| LevelInfo | |
| LevelWarn | |
| LevelError | |
| LevelOther Text |
levelTrace :: LogLevel Source #
Since: 0.1
levelFatal :: LogLevel Source #
Since: 0.1
Logging functions
Levels
Generates a function that takes a Text and logs a LevelDebug message. Usage:
$(logDebug) "This is a debug log message"
logOther :: Text -> Q Exp Source #
Generates a function that takes a Text and logs a LevelOther message. Usage:
$(logOther "My new level") "This is a log message"
Level checks
Arguments
| :: Applicative f | |
| => LogLevel | The configured log level to check against. |
| -> LogLevel | The log level for this action. |
| -> f () | The logging action to run if the level passes. |
| -> f () |
guardLevel configLvl lvl m runs m iff .
This can be useful for writing a logging function e.g.shouldLog configLvl lvl
-- logs msg to file iff configLogLevel <= lvl e.g. -- configLogLevel :=LevelWarn-- lvl :=LevelErrorlogMsg lvl msg = do configLogLevel <- getConfigLogLevel -- e.g. ReaderT Env guardLevel configLogLevel lvl $ do logToFile msg
Since: 0.1
Arguments
| :: LogLevel | The configured log level to check against. |
| -> LogLevel | Level for this log |
| -> Bool | Whether we should log |
shouldLog configLvl lvl returns true iff configLvl <= lvl. Uses
LogLevel's built-in ordering with special cases for Trace
(LevelOther Trace) and Fatal (LevelOther Fatal). The ad-hoc
ordering is thus:
LevelOther "Trace"
< LevelDebug
< LevelInfo
< LevelWarn
< LevelError
< LevelOther "Fatal"
< LevelOther "<any>"
In other words, LogLevel's usual Ord is respected, with the additional
cases. Note that any other LevelOther "custom" sit at the the highest
level and compare via Text's Ord, just like LogLevel's usual Ord.
Since: 0.1
Formatting
data LogFormatter Source #
Formatter for logs.
Since: 0.1
Constructors
| MkLogFormatter | |
Fields
| |
Instances
defaultLogFormatter :: Loc -> LogFormatter Source #
LogFormatter with:
locStrategy =LocPartialloc newline =TruethreadLabel =Falsetimezone =False
Since: 0.1
data LocStrategy Source #
Determines how we log location data.
Since: 0.1
Constructors
| LocPartial !Loc | Logs the location with filename, line, col. Since: 0.1 |
| LocStable !Loc | Logs the location with filename. Since: 0.1 |
| LocNone | No location logging. Since: 0.1 |
Instances
| Generic LocStrategy Source # | |||||
Defined in Effects.Logger.Utils Associated Types
| |||||
| Show LocStrategy Source # | Since: 0.1 | ||||
Defined in Effects.Logger.Utils Methods showsPrec :: Int -> LocStrategy -> ShowS # show :: LocStrategy -> String # showList :: [LocStrategy] -> ShowS # | |||||
| Eq LocStrategy Source # | Since: 0.1 | ||||
Defined in Effects.Logger.Utils | |||||
| type Rep LocStrategy Source # | Since: 0.1 | ||||
Defined in Effects.Logger.Utils type Rep LocStrategy = D1 ('MetaData "LocStrategy" "Effects.Logger.Utils" "effects-logger-0.1-inplace" 'False) (C1 ('MetaCons "LocPartial" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Loc)) :+: (C1 ('MetaCons "LocStable" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Loc)) :+: C1 ('MetaCons "LocNone" 'PrefixI 'False) (U1 :: Type -> Type))) | |||||
Arguments
| :: (HasCallStack, MonadThread m, MonadTime m, ToLogStr msg) | |
| => LogFormatter | Formatter to use. |
| -> LogLevel | The level in which to log. |
| -> msg | Message. |
| -> m LogStr | Formatted LogStr. |
Produces a formatted LogStr.
Example
-- [timestamp][thread_label][code_loc][level] msg [2022-02-08 10:20:05][thread-label][filename:1:2][Warn] msg
Since: 0.1
Optics
LogLevels
_LevelTrace :: Prism' LogLevel () Source #
Since: 0.1
_LevelInfo :: Prism' LogLevel () Source #
Since: 0.1
_LevelDebug :: Prism' LogLevel () Source #
Since: 0.1
_LevelWarn :: Prism' LogLevel () Source #
Since: 0.1
_LevelError :: Prism' LogLevel () Source #
Since: 0.1
_LevelFatal :: Prism' LogLevel () Source #
Since: 0.1
Reexports
Log message builder. Use (<>) to append two LogStr in O(1).
A location within a source file.
Instances
| Data Loc # | |||||
Defined in GHC.Internal.TH.Syntax Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Loc -> c Loc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Loc # dataTypeOf :: Loc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Loc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Loc) # gmapT :: (forall b. Data b => b -> b) -> Loc -> Loc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQ :: (forall d. Data d => d -> u) -> Loc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Loc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # | |||||
| Generic Loc # | |||||
Defined in GHC.Internal.TH.Syntax Associated Types
| |||||
| Show Loc # | |||||
| Eq Loc # | |||||
| Ord Loc # | |||||
| Lift Loc # | Since: template-haskell-2.22.1.0 | ||||
| type Rep Loc # | |||||
Defined in GHC.Internal.TH.Syntax type Rep Loc = D1 ('MetaData "Loc" "GHC.Internal.TH.Syntax" "ghc-internal" 'False) (C1 ('MetaCons "Loc" 'PrefixI 'True) ((S1 ('MetaSel ('Just "loc_filename") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "loc_package") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :*: (S1 ('MetaSel ('Just "loc_module") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "loc_start") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CharPos) :*: S1 ('MetaSel ('Just "loc_end") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CharPos))))) | |||||