implicit-logging-0.1.0.0: A logging framework built around implicit parameters.

Copyright(C) 2016 Rev. Johnny Healey
LicenseLGPL-3
MaintainerRev. Johnny Healey <rev.null@gmail.com>
Stabilityexperimental
Portabilityunknown
Safe HaskellSafe
LanguageHaskell2010

Control.Logging

Contents

Description

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.

Synopsis

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.

newtype LATime Source

LogAnnotation to log the current time. The String argument should provide the desired time formatting string.

Constructors

LAT String 

newtype LAContext c Source

LogAnnotation to log a String derived from the context.

Constructors

LC (c -> String) 

Instances

data LALevel Source

LogAnnotation to log the Level,

Constructors

LALevel 

data LAThread Source

LogAnnotation to log the current ThreadId

Constructors

LAThread 

data LogConfig c Source

Log Configuration

Constructors

LogConfig 

Fields

logLevel :: Level

The minimum Level to log

logHeader :: [LogHeader c]

The list of LogHeader wrapped annotations to display on every line.

logIO :: String -> IO ()

The IO command to log a line.

logContext :: c

The user-defined context for logging.

data LogHeader c Source

A LogHeader wraps a LogAnnotation with existential quantifcation.

Constructors

forall l . LogAnnotation c l => LH l 

Log Configuration

defaultLogConfig :: c -> LogConfig c Source

The default LogConfig for logging to stdout. Takes the logContext as an argument. This logs the time and Level.

fileLogConfig :: FilePath -> c -> IO (LogConfig c) Source

The default LogConfig that opens a file for logging.

handleLogConfig :: Handle -> c -> IO (LogConfig c) Source

The default LogConfig that is provided a Handle for logging.

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.

logPrint :: (MonadIO m, Show s, Logging c) => Level -> s -> m () Source

Write an instance of Show to the log with the specified Level.

debug :: (MonadIO m, Logging c) => String -> m () Source

Log a line at the Debug Level.

printDebug :: (MonadIO m, Show s, Logging c) => s -> m () Source

Log an instance of Show at the Debug Level.

info :: (MonadIO m, Logging c) => String -> m () Source

Log a line at the Info Level.

printInfo :: (MonadIO m, Show s, Logging c) => s -> m () Source

Log an instance of Show at the Info Level.

warn :: (MonadIO m, Logging c) => String -> m () Source

Log a line at the Warn Level.

printWarn :: (MonadIO m, Show s, Logging c) => s -> m () Source

Log an instance of Show at the Warn Level.

err :: (MonadIO m, Logging c) => String -> m () Source

Log a line at the Err Level.

printErr :: (MonadIO m, Show s, Logging c) => s -> m () Source

Log an instance of Show at the Err Level.

crit :: (MonadIO m, Logging c) => String -> m () Source

Log a line at the Crit Level.

printCrit :: (MonadIO m, Show s, Logging c) => s -> m () Source

Log an instance of Show at the Crit Level.