dap
Safe HaskellNone
LanguageHaskell2010

DAP.Log

Synopsis

Documentation

data DebugStatus Source #

Constructors

SENT 
RECEIVED 

Instances

Instances details
Show DebugStatus Source # 
Instance details

Defined in DAP.Log

Eq DebugStatus Source # 
Instance details

Defined in DAP.Log

newtype LogAction (m :: Type -> Type) msg #

Polymorphic and very general logging action type.

  • msg type variables is an input for logger. It can be Text or custom logging messsage with different fields that you want to format in future.
  • m type variable is for monadic action inside which logging is happening. It can be either IO or some custom pure monad.

Key design point here is that LogAction is:

Constructors

LogAction 

Fields

Instances

Instances details
Contravariant (LogAction m) 
Instance details

Defined in Colog.Core.Action

Methods

contramap :: (a' -> a) -> LogAction m a -> LogAction m a' #

(>$) :: b -> LogAction m b -> LogAction m a #

UnrepresentableClass => Functor (LogAction m)

⚠️CAUTION⚠️ This instance is for custom error display only.

LogAction is not supposed to have Functor instance by design.

In case it is used by mistake, the user will see the following:

>>> fmap show logStringStdout
...
... 'LogAction' cannot have a 'Functor' instance by design.
      However, you've attempted to use this instance.
...
      Probably you meant 'Contravariant' class instance with the following methods:
        * contramap :: (a -> b) -> LogAction m b -> LogAction m a
        * (>$) :: b -> LogAction m b -> LogAction m a
...

# 207 "srcCologCore/Action.hs"

Since: co-log-core-0.2.1.0

Instance details

Defined in Colog.Core.Action

Methods

fmap :: (a -> b) -> LogAction m a -> LogAction m b #

(<$) :: a -> LogAction m b -> LogAction m a #

Applicative m => Monoid (LogAction m a) 
Instance details

Defined in Colog.Core.Action

Methods

mempty :: LogAction m a #

mappend :: LogAction m a -> LogAction m a -> LogAction m a #

mconcat :: [LogAction m a] -> LogAction m a #

Applicative m => Semigroup (LogAction m a)

This instance allows you to join multiple logging actions into single one.

For example, if you have two actions like these:

logToStdout :: LogAction IO String  -- outputs String to terminal
logToFile   :: LogAction IO String  -- appends String to some file

You can create new LogAction that perform both actions one after another using Semigroup:

logToBoth :: LogAction IO String  -- outputs String to both terminal and some file
logToBoth = logToStdout <> logToFile
Instance details

Defined in Colog.Core.Action

Methods

(<>) :: LogAction m a -> LogAction m a -> LogAction m a #

sconcat :: NonEmpty (LogAction m a) -> LogAction m a #

stimes :: Integral b => b -> LogAction m a -> LogAction m a #

HasLog (LogAction m msg) msg m 
Instance details

Defined in Colog.Core.Class

Methods

getLogAction :: LogAction m msg -> LogAction m msg #

setLogAction :: LogAction m msg -> LogAction m msg -> LogAction m msg #

overLogAction :: (LogAction m msg -> LogAction m msg) -> LogAction m msg -> LogAction m msg #

logActionL :: Lens' (LogAction m msg) (LogAction m msg) #

data Level Source #

Constructors

DEBUG 
INFO 
WARN 
ERROR 

Instances

Instances details
Show Level Source # 
Instance details

Defined in DAP.Log

Methods

showsPrec :: Int -> Level -> ShowS #

show :: Level -> String #

showList :: [Level] -> ShowS #

Eq Level Source # 
Instance details

Defined in DAP.Log

Methods

(==) :: Level -> Level -> Bool #

(/=) :: Level -> Level -> Bool #

(<&) :: LogAction m msg -> msg -> m () infix 5 #

Operator version of unLogAction. Note that because of the types, something like:

action <& msg1 <& msg2

doesn't make sense. Instead you want:

action <& msg1 >> action <& msg2

In addition, because <& has higher precedence than the other operators in this module, the following:

f >$< action <& msg

is equivalent to:

(f >$< action) <& msg

cmap :: forall a b (m :: Type -> Type). (a -> b) -> LogAction m b -> LogAction m a #

This combinator is contramap from contravariant functor. It is useful when you have something like

data LogRecord = LR
    { lrName    :: LoggerName
    , lrMessage :: Text
    }

and you need to provide LogAction which consumes LogRecord

logRecordAction :: LogAction m LogRecord

when you only have action that consumes Text

logTextAction :: LogAction m Text

With cmap you can do the following:

logRecordAction :: LogAction m LogRecord
logRecordAction = cmap lrMesssage logTextAction

This action will print only lrMessage from LogRecord. But if you have formatting function like this:

formatLogRecord :: LogRecord -> Text

you can apply it instead of lrMessage to log formatted LogRecord as Text.

cfilter :: forall (m :: Type -> Type) msg. Applicative m => (msg -> Bool) -> LogAction m msg -> LogAction m msg #

Takes predicate and performs given logging action only if predicate returns True on input logging message.