yet-another-logger-0.3.1: Yet Another Logger

CopyrightCopyright (c) 2016-2018 Lars Kuhtz <lakuhtz@gmail.com>
Copyright (c) 2014-2015 PivotCloud Inc.
LicenseApache License, Version 2.0
MaintainerLars Kuhtz <lakuhtz@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

System.Logger.Types

Contents

Description

 
Synopsis

LogLevel

data LogLevel Source #

Constructors

Quiet 
Error 
Warn 
Info 
Debug 
Instances
Bounded LogLevel Source # 
Instance details

Defined in System.Logger.Types

Enum LogLevel Source # 
Instance details

Defined in System.Logger.Types

Eq LogLevel Source # 
Instance details

Defined in System.Logger.Types

Ord LogLevel Source # 
Instance details

Defined in System.Logger.Types

Read LogLevel Source # 
Instance details

Defined in System.Logger.Types

Show LogLevel Source # 
Instance details

Defined in System.Logger.Types

Generic LogLevel Source # 
Instance details

Defined in System.Logger.Types

Associated Types

type Rep LogLevel :: * -> * #

Methods

from :: LogLevel -> Rep LogLevel x #

to :: Rep LogLevel x -> LogLevel #

NFData LogLevel Source # 
Instance details

Defined in System.Logger.Types

Methods

rnf :: LogLevel -> () #

ToJSON LogLevel Source # 
Instance details

Defined in System.Logger.Types

FromJSON LogLevel Source # 
Instance details

Defined in System.Logger.Types

type Rep LogLevel Source # 
Instance details

Defined in System.Logger.Types

type Rep LogLevel = D1 (MetaData "LogLevel" "System.Logger.Types" "yet-another-logger-0.3.1-9xkv1iYSnq3IJ3TK3FoqRe" False) ((C1 (MetaCons "Quiet" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Error" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Warn" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "Info" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Debug" PrefixI False) (U1 :: * -> *))))

pLogLevel_ Source #

Arguments

:: Text

prefix for the command line options.

-> Parser LogLevel 

A version of pLogLevel that takes a prefix for the command line option.

Since: yet-another-logger-0.2

LogPolicy

data LogPolicy Source #

Policy that determines how the case of a congested logging pipeline is addressed.

Instances
Bounded LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Enum LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Eq LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Ord LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Read LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Show LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Generic LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Associated Types

type Rep LogPolicy :: * -> * #

NFData LogPolicy Source # 
Instance details

Defined in System.Logger.Types

Methods

rnf :: LogPolicy -> () #

ToJSON LogPolicy Source # 
Instance details

Defined in System.Logger.Types

FromJSON LogPolicy Source # 
Instance details

Defined in System.Logger.Types

type Rep LogPolicy Source # 
Instance details

Defined in System.Logger.Types

type Rep LogPolicy = D1 (MetaData "LogPolicy" "System.Logger.Types" "yet-another-logger-0.3.1-9xkv1iYSnq3IJ3TK3FoqRe" False) (C1 (MetaCons "LogPolicyDiscard" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "LogPolicyRaise" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "LogPolicyBlock" PrefixI False) (U1 :: * -> *)))

pLogPolicy_ Source #

Arguments

:: Text

prefix for the command line options.

-> Parser LogPolicy 

A version of pLogPolicy that takes a prefix for the command line option.

Since: yet-another-logger-0.2

LogLabel

Logger Exception

data LoggerException a where Source #

Exceptions that are thrown by the logger

QueueFullException
thrown when the queue is full and the logger policy is set to throw exceptions on a full queue
BackendTerminatedException
a backend can throw this exception to force the logger immediately
BackendTooManyExceptions
thrown when the backend has thrown unexpected exceptions more than loggerConfigExceptionLimit times

Since: yet-another-logger-0.2

Logger Backend

data LogMessage a Source #

The Internal log message type.

The type parameter a is expected to provide intances of Show, Typeable, and NFData.

If we need to support different backends, we may consider including the backend here...

Constructors

LogMessage 

Fields

  • _logMsg :: !a
     
  • _logMsgLevel :: !LogLevel
     
  • _logMsgScope :: !LogScope

    efficiency of this depends on whether this is shared between log messsages. Usually this should be just a pointer to a shared list.

  • _logMsgTime :: !TimeSpec

    a POSIX timestamp

    UTC seconds elapsed since UNIX Epoch as returned by clock_gettime on the respective system. NOTE that POSIX is ambigious with regard to treatment of leap seconds, and some implementations may actually return TAI.

    Since: yet-another-logger-0.2

Instances
Eq a => Eq (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Methods

(==) :: LogMessage a -> LogMessage a -> Bool #

(/=) :: LogMessage a -> LogMessage a -> Bool #

Ord a => Ord (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Read a => Read (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Show a => Show (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Generic (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Associated Types

type Rep (LogMessage a) :: * -> * #

Methods

from :: LogMessage a -> Rep (LogMessage a) x #

to :: Rep (LogMessage a) x -> LogMessage a #

NFData a => NFData (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

Methods

rnf :: LogMessage a -> () #

type Rep (LogMessage a) Source # 
Instance details

Defined in System.Logger.Types

type Rep (LogMessage a) = D1 (MetaData "LogMessage" "System.Logger.Types" "yet-another-logger-0.3.1-9xkv1iYSnq3IJ3TK3FoqRe" False) (C1 (MetaCons "LogMessage" PrefixI True) ((S1 (MetaSel (Just "_logMsg") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a) :*: S1 (MetaSel (Just "_logMsgLevel") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LogLevel)) :*: (S1 (MetaSel (Just "_logMsgScope") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LogScope) :*: S1 (MetaSel (Just "_logMsgTime") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 TimeSpec))))

logMsgTime :: Lens' (LogMessage a) TimeSpec Source #

Since: yet-another-logger-0.2

type LoggerBackend a = Either (LogMessage Text) (LogMessage a) -> IO () Source #

This is given to logger when it is created. It formats and delivers individual log messages synchronously. The backend is called once for each log message (that meets the required log level).

The type parameter a is expected to provide instances for Show Typeable, and NFData.

The Left values of the argument allows the generation of log messages that are independent of the parameter a. The motivation for this is reporting issues in Logging system itself, like a full logger queue or providing statistics about the fill level of the queue. There may be other uses of this, too.

Backends that can fail are encouraged (but not forced) to take into account the LogPolicy that is effective for a message. For instance, a backend may implement a reasonable retry logic for each message and then raise a BackendTerminatedException in case the policy is LogPolicyBlock or LogPolicyRaise (thus causing the logger to exit immediately) and raise some other exception otherwise (thus discarding the message without causing the logger to not exit immediately). In addition a backend might retry harder in case of LogPolicyBlock.

TODO there may be scenarios where chunked processing is beneficial. While this can be done in a closure of this function, more direct support might be desirable.

Logger Frontend

type LogFunction a m = LogLevel -> a -> m () Source #

type LogFunctionIO a = LogLevel -> a -> IO () Source #

This function is provided by the logger.

LoggerCtx

class LoggerCtx ctx msg | ctx -> msg where Source #

Abstraction of a logger context that can be used without dependening on a specific monadic context.

The loggerFunIO incorporates a LoggerBackend. An instance of a LoggerCtx is free to use a hard coded LoggerBackend or to be usable with different LoggerBackend functions. The latter is recommended but not required.

You don't have to provide an instance of this for your logger. Instead you may just provide an instance of MonadLog directly.

If this doesn't fit your needs you may use a newtype wrapper and define your own instances.

Methods

loggerFunIO :: (Show msg, Typeable msg, NFData msg) => ctx -> LogFunctionIO msg Source #

setLoggerLevel :: Setter' ctx LogLevel Source #

setLoggerScope :: Setter' ctx LogScope Source #

setLoggerPolicy :: Setter' ctx LogPolicy Source #

withLoggerLevel :: LogLevel -> ctx -> (ctx -> α) -> α Source #

withLoggerLabel :: LogLabel -> ctx -> (ctx -> α) -> α Source #

withLoggerPolicy :: LogPolicy -> ctx -> (ctx -> α) -> α Source #

data LoggerCtxT ctx m α Source #

Instances
Monad m => MonadReader ctx (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

ask :: LoggerCtxT ctx m ctx #

local :: (ctx -> ctx) -> LoggerCtxT ctx m a -> LoggerCtxT ctx m a #

reader :: (ctx -> a) -> LoggerCtxT ctx m a #

MonadState a m => MonadState a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

get :: LoggerCtxT ctx m a #

put :: a -> LoggerCtxT ctx m () #

state :: (a -> (a0, a)) -> LoggerCtxT ctx m a0 #

MonadWriter a m => MonadWriter a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

writer :: (a0, a) -> LoggerCtxT ctx m a0 #

tell :: a -> LoggerCtxT ctx m () #

listen :: LoggerCtxT ctx m a0 -> LoggerCtxT ctx m (a0, a) #

pass :: LoggerCtxT ctx m (a0, a -> a) -> LoggerCtxT ctx m a0 #

MonadError a m => MonadError a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

throwError :: a -> LoggerCtxT ctx m a0 #

catchError :: LoggerCtxT ctx m a0 -> (a -> LoggerCtxT ctx m a0) -> LoggerCtxT ctx m a0 #

MonadBase a m => MonadBase a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

liftBase :: a α -> LoggerCtxT ctx m α #

MonadBaseControl b m => MonadBaseControl b (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Associated Types

type StM (LoggerCtxT ctx m) a :: * #

Methods

liftBaseWith :: (RunInBase (LoggerCtxT ctx m) b -> b a) -> LoggerCtxT ctx m a #

restoreM :: StM (LoggerCtxT ctx m) a -> LoggerCtxT ctx m a #

(Show a, Typeable a, NFData a, MonadIO m, LoggerCtx ctx a) => MonadLog a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

logg :: LogFunction a (LoggerCtxT ctx m) Source #

withLevel :: LogLevel -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

withPolicy :: LogPolicy -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

localScope :: (LogScope -> LogScope) -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

MonadTrans (LoggerCtxT ctx) Source # 
Instance details

Defined in System.Logger.Types

Methods

lift :: Monad m => m a -> LoggerCtxT ctx m a #

MonadTransControl (LoggerCtxT ctx) Source # 
Instance details

Defined in System.Logger.Types

Associated Types

type StT (LoggerCtxT ctx) a :: * #

Methods

liftWith :: Monad m => (Run (LoggerCtxT ctx) -> m a) -> LoggerCtxT ctx m a #

restoreT :: Monad m => m (StT (LoggerCtxT ctx) a) -> LoggerCtxT ctx m a #

Monad m => Monad (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

(>>=) :: LoggerCtxT ctx m a -> (a -> LoggerCtxT ctx m b) -> LoggerCtxT ctx m b #

(>>) :: LoggerCtxT ctx m a -> LoggerCtxT ctx m b -> LoggerCtxT ctx m b #

return :: a -> LoggerCtxT ctx m a #

fail :: String -> LoggerCtxT ctx m a #

Functor m => Functor (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

fmap :: (a -> b) -> LoggerCtxT ctx m a -> LoggerCtxT ctx m b #

(<$) :: a -> LoggerCtxT ctx m b -> LoggerCtxT ctx m a #

Applicative m => Applicative (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

pure :: a -> LoggerCtxT ctx m a #

(<*>) :: LoggerCtxT ctx m (a -> b) -> LoggerCtxT ctx m a -> LoggerCtxT ctx m b #

liftA2 :: (a -> b -> c) -> LoggerCtxT ctx m a -> LoggerCtxT ctx m b -> LoggerCtxT ctx m c #

(*>) :: LoggerCtxT ctx m a -> LoggerCtxT ctx m b -> LoggerCtxT ctx m b #

(<*) :: LoggerCtxT ctx m a -> LoggerCtxT ctx m b -> LoggerCtxT ctx m a #

MonadIO m => MonadIO (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

liftIO :: IO a -> LoggerCtxT ctx m a #

MonadThrow m => MonadThrow (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

throwM :: Exception e => e -> LoggerCtxT ctx m a #

MonadCatch m => MonadCatch (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

catch :: Exception e => LoggerCtxT ctx m a -> (e -> LoggerCtxT ctx m a) -> LoggerCtxT ctx m a #

MonadMask m => MonadMask (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

mask :: ((forall a. LoggerCtxT ctx m a -> LoggerCtxT ctx m a) -> LoggerCtxT ctx m b) -> LoggerCtxT ctx m b #

uninterruptibleMask :: ((forall a. LoggerCtxT ctx m a -> LoggerCtxT ctx m a) -> LoggerCtxT ctx m b) -> LoggerCtxT ctx m b #

generalBracket :: LoggerCtxT ctx m a -> (a -> ExitCase b -> LoggerCtxT ctx m c) -> (a -> LoggerCtxT ctx m b) -> LoggerCtxT ctx m (b, c) #

type StT (LoggerCtxT ctx) a Source # 
Instance details

Defined in System.Logger.Types

type StT (LoggerCtxT ctx) a = StT (ReaderT ctx :: (* -> *) -> * -> *) a
type StM (LoggerCtxT ctx m) a Source # 
Instance details

Defined in System.Logger.Types

type StM (LoggerCtxT ctx m) a = ComposeSt (LoggerCtxT ctx) m a

runLoggerCtxT :: LoggerCtxT ctx m α -> ctx -> m α Source #

MonadLog

class Monad m => MonadLog a m | m -> a where Source #

Minimal complete definition

logg, withLevel, withPolicy, localScope

Methods

logg :: LogFunction a m Source #

Log a message.

withLevel :: LogLevel -> m α -> m α Source #

Run the inner computation with the given LogLevel

withPolicy :: LogPolicy -> m α -> m α Source #

Run the inner computation with the given LogPolicy.

localScope :: (LogScope -> LogScope) -> m α -> m α Source #

Run the inner computation with a modified LogScope.

Since: yet-another-logger-0.1

Instances
(Show a, Typeable a, NFData a, MonadIO m, LoggerCtx ctx a) => MonadLog a (LoggerCtxT ctx m) Source # 
Instance details

Defined in System.Logger.Types

Methods

logg :: LogFunction a (LoggerCtxT ctx m) Source #

withLevel :: LogLevel -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

withPolicy :: LogPolicy -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

localScope :: (LogScope -> LogScope) -> LoggerCtxT ctx m α -> LoggerCtxT ctx m α Source #

MonadLog a m => MonadLog a (StateT σ m) Source # 
Instance details

Defined in System.Logger.Types

Methods

logg :: LogFunction a (StateT σ m) Source #

withLevel :: LogLevel -> StateT σ m α -> StateT σ m α Source #

withPolicy :: LogPolicy -> StateT σ m α -> StateT σ m α Source #

localScope :: (LogScope -> LogScope) -> StateT σ m α -> StateT σ m α Source #

MonadLog a m => MonadLog a (ExceptT ε m) Source # 
Instance details

Defined in System.Logger.Types

Methods

logg :: LogFunction a (ExceptT ε m) Source #

withLevel :: LogLevel -> ExceptT ε m α -> ExceptT ε m α Source #

withPolicy :: LogPolicy -> ExceptT ε m α -> ExceptT ε m α Source #

localScope :: (LogScope -> LogScope) -> ExceptT ε m α -> ExceptT ε m α Source #

(Monoid σ, MonadLog a m) => MonadLog a (WriterT σ m) Source # 
Instance details

Defined in System.Logger.Types

Methods

logg :: LogFunction a (WriterT σ m) Source #

withLevel :: LogLevel -> WriterT σ m α -> WriterT σ m α Source #

withPolicy :: LogPolicy -> WriterT σ m α -> WriterT σ m α Source #

localScope :: (LogScope -> LogScope) -> WriterT σ m α -> WriterT σ m α Source #

withLabel :: MonadLog a m => LogLabel -> m α -> m α Source #

Append a LogLabel to the current LogScope when executing the inner computation. The LogScope of the outer computation is unchanged.

Since: yet-another-logger-0.1

clearScope :: MonadLog a m => m α -> m α Source #

Executing the inner computation with an empty LogScope. The LogScope of the outer computation is unchanged.

Since: yet-another-logger-0.1

popLabel :: MonadLog a m => m α -> m α Source #

Remove the last LogLabel from the current LogScope when executing the inner computation. The LogScope of the outer computation is unchanged.

Since: yet-another-logger-0.1

Orphan instances

NFData TimeSpec Source # 
Instance details

Methods

rnf :: TimeSpec -> () #