Copyright | (C) 2016 Rev. Johnny Healey |
---|---|
License | LGPL-3 |
Maintainer | Rev. Johnny Healey <rev.null@gmail.com> |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe |
Language | Haskell2010 |
This library provides a simple framework for adding logging to an application. Log configuration is passed around via implicit parameters. Each logging configuration can carry around some bit of state that can be used to annotate log lines.
- data Level
- type LogFormatter c = MaybeT (ReaderT (c, Level) IO)
- getLogLevel :: LogFormatter c Level
- getLogContext :: LogFormatter c c
- class LogAnnotation c l where
- logFormat :: l -> LogFormatter c String
- newtype LATime = LAT String
- newtype LAContext c = LC (c -> String)
- data LALevel = LALevel
- data LAThread = LAThread
- data LogConfig c = LogConfig {}
- data LogHeader c = forall l . LogAnnotation c l => LH l
- defaultLogConfig :: c -> LogConfig c
- fileLogConfig :: FilePath -> c -> IO (LogConfig c)
- handleLogConfig :: Handle -> c -> IO (LogConfig c)
- type Logging c = ?log :: LogConfig c
- runLogging :: LogConfig c -> (Logging c => a) -> a
- withLogContext :: Logging c => (c -> c) -> (Logging c => a) -> a
- withLogHeader :: (Logging c, LogAnnotation c l) => l -> (Logging c => a) -> a
- withLogLevel :: Logging c => Level -> (Logging c => a) -> a
- logLine :: (MonadIO m, Logging c) => Level -> String -> m ()
- logPrint :: (MonadIO m, Show s, Logging c) => Level -> s -> m ()
- debug :: (MonadIO m, Logging c) => String -> m ()
- printDebug :: (MonadIO m, Show s, Logging c) => s -> m ()
- info :: (MonadIO m, Logging c) => String -> m ()
- printInfo :: (MonadIO m, Show s, Logging c) => s -> m ()
- warn :: (MonadIO m, Logging c) => String -> m ()
- printWarn :: (MonadIO m, Show s, Logging c) => s -> m ()
- err :: (MonadIO m, Logging c) => String -> m ()
- printErr :: (MonadIO m, Show s, Logging c) => s -> m ()
- crit :: (MonadIO m, Logging c) => String -> m ()
- printCrit :: (MonadIO m, Show s, Logging c) => s -> m ()
Log Levels
Log Levels
Log Annotations
type LogFormatter c = MaybeT (ReaderT (c, Level) IO) Source
The LogFormatter
monad is for converting a LogAnnotation
to String
.
getLogLevel :: LogFormatter c Level Source
Returns the current log Level
.
getLogContext :: LogFormatter c c Source
Returns the current log context.
class LogAnnotation c l where Source
A LogAnnotation
is a typeclass to establish that an annotation can be
used for logging in the log context c
.
logFormat :: l -> LogFormatter c String Source
LogAnnotation
to log the current time. The String
argument should
provide the desired time formatting string.
LogAnnotation
to log a String derived from the context.
LogAnnotation c (LAContext c) Source |
LogAnnotation
to log the current ThreadId
Log Configuration
A LogHeader
wraps a LogAnnotation
with existential quantifcation.
forall l . LogAnnotation c l => LH l |
Log Configuration
defaultLogConfig :: c -> LogConfig c Source
fileLogConfig :: FilePath -> c -> IO (LogConfig c) Source
The default LogConfig
that opens a file for logging.
handleLogConfig :: Handle -> c -> IO (LogConfig c) Source
Log Runners
type Logging c = ?log :: LogConfig c Source
Logging
is just a Constraint synonym to denote that logging is
available in a function.
runLogging :: LogConfig c -> (Logging c => a) -> a Source
Evaluate a value with the provided LogConfig
withLogContext :: Logging c => (c -> c) -> (Logging c => a) -> a Source
Evaluate a value with the log context modified by the provided function.
withLogHeader :: (Logging c, LogAnnotation c l) => l -> (Logging c => a) -> a Source
Evaluate a value with an additional LogAnnotation
added to the header.
withLogLevel :: Logging c => Level -> (Logging c => a) -> a Source
Evaluate a value with the specified minimum Level
.
Log Invocation
logLine :: (MonadIO m, Logging c) => Level -> String -> m () Source
Write a line to the log with the specified Level
.
printDebug :: (MonadIO m, Show s, Logging c) => s -> m () Source