co-log-0.2.0: Composable Contravariant Comonadic Logging Library

Safe HaskellNone
LanguageHaskell2010

Colog.Message

Contents

Description

Message with Severity, and logging functions for them.

Synopsis

Basic message type

data Message Source #

Consist of the message Severity level and the message itself.

unMessageField :: forall fieldName m. MessageField m fieldName -> m (FieldType fieldName) Source #

log :: WithLog env Message m => Severity -> Text -> m () Source #

Logs the message with given Severity.

logDebug :: WithLog env Message m => Text -> m () Source #

Logs the message with Debug severity.

logInfo :: WithLog env Message m => Text -> m () Source #

Logs the message with Info severity.

logWarning :: WithLog env Message m => Text -> m () Source #

Logs the message with Warning severity.

logError :: WithLog env Message m => Text -> m () Source #

Logs the message with Error severity.

logException :: forall e m env. (WithLog env Message m, Exception e) => e -> m () Source #

Logs Exception message.

fmtMessage :: Message -> Text Source #

Prettifies Message type.

Externally extensible message type

type family FieldType (fieldName :: Symbol) :: Type Source #

Open type family that maps some user defined tags (type names) to actual types. The type family is open so you can add new instances.

Instances
type FieldType "threadId" Source # 
Instance details

Defined in Colog.Message

type FieldType "threadId" = ThreadId
type FieldType "utcTime" Source # 
Instance details

Defined in Colog.Message

type FieldType "utcTime" = UTCTime

newtype MessageField (m :: Type -> Type) (fieldName :: Symbol) where Source #

newtype wrapper. Stores monadic ability to extract value of FieldType.

Implementation detail: this exotic writing of MessageField is required in order to use it nicer with type applications. So users can write

MessageField @"threadId" myThreadId

instead of

MessageField _ "threadId" myThreadId

Simpler version of this newtype:

newtype MessageField m fieldName = MessageField
    { unMesssageField :: m (FieldType fieldName)
    }

Constructors

MessageField :: forall fieldName m. m (FieldType fieldName) -> MessageField m fieldName 
Instances
(KnownSymbol fieldName, a ~ m (FieldType fieldName)) => IsLabel fieldName (a -> WrapTypeable (MessageField m)) Source # 
Instance details

Defined in Colog.Message

Methods

fromLabel :: a -> WrapTypeable (MessageField m) #

type FieldMap (m :: Type -> Type) = TypeRepMap (MessageField m) Source #

Depedent map from type level strings to the corresponding types. See FieldType for mapping between names and types.

defaultFieldMap :: MonadIO m => FieldMap m Source #

Default message map that contains actions to extract ThreadId and UTCTime. Basically, the following mapping:

"threadId" -> myThreadId
"utcTime"  -> getCurrentTime

data RichMessage (m :: Type -> Type) Source #

Contains additional data to Message to display more verbose information.

fmtRichMessageDefault :: MonadIO m => RichMessage m -> m Text Source #

Formats RichMessage in the following way:

[Severity] [Time] [SourceLocation] [ThreadId] message

upgradeMessageAction :: forall m. FieldMap m -> LogAction m (RichMessage m) -> LogAction m Message Source #

Allows to extend basic Message type with given dependent map of fields.