co-log-json-0.1.0.0: Structured messages support in co-log ecosystem.
Safe HaskellNone
LanguageHaskell2010

Colog.Json.Internal.Structured

Description

Structure for tracing context.

We assume that each message (Message) can be tagged with two types of values:

  • segment - path that tells where are we in the codebase.
  • attrbibutes - additional key-value tags, where value is an arbitrary json object.

Segment is needed in a case if we want to apply differrent logging rules to the differrent parts of the codebase. For example we may way to log all the messages in the component one but not all the rest.

In addition each Message provides some common fields:

  • "thread" - id of the thread that emits message
  • "severity" - message severity

All messages in the same context share segment and attributes. So when exported to the log analytics systems it's easy to load all the information associated with it.

  • *Compatibility note** internal structure of the message may be changed in the future in case if it's proven that another implementation is faster or more memory efficient. However the higher level API is likely to be stable.
Synopsis

Log datastructure.

data Structured Source #

Part of the structured message.

Constructors

Segment Text

Part of the message that is associated this the context of code.

Attr Text Encoding

Add attribute to the list.

data Message Source #

Log message.

Constructors

Message 

Fields

newtype LogStr Source #

Efficient message builder.

Constructors

LogStr Builder 

Instances

Instances details
IsString LogStr Source # 
Instance details

Defined in Colog.Json.Internal.Structured

Methods

fromString :: String -> LogStr #

Monoid LogStr Source # 
Instance details

Defined in Colog.Json.Internal.Structured

Semigroup LogStr Source # 
Instance details

Defined in Colog.Json.Internal.Structured

newtype PushContext Source #

Wrapper over the structured message builder.

Internals.

data Severity Source #

Logger severity.

Constructors

DebugS

Debug level, intended for internal information

InfoS

Info level, that may be interesting to the user

NoticeS

Notice, information that

WarningS

Warning, information possible problem problem of some sort

ErrorS

Error, information about a problem

CriticalS

Critical error, intended for error that may break the system

AlertS

Critical error where immediate actions should be taken

EmergencyS

System wide emergency

encodeSeverity :: Severity -> Encoding Source #

Convert severity into the one accepted by the loger.

showLS :: Show a => a -> LogStr Source #

Convert loggable value from any message that has show instance.

ls :: StringConv a Text => a -> LogStr Source #

Convert message can be converted.

sl :: ToJSON a => Text -> a -> PushContext Source #

"Simple logger" adds a key value to the context:

sl "foo" 123

Will add "foo":123 key pair to the current list of the attributes. Submitted value is stored with json encoding.

mkThreadId :: ThreadId -> Int Source #

Helper function to get id of the thread.