Safe Haskell | Trustworthy |
---|
This module defines the Format
datatype that describes how to format a log line.
It also defines a template function $(format _) ::
that allows C-style string formatting.
The format string is thus parsed at compile time.
Format
The format string may contain the following elements:
- %m - The logged message
- %s - The severity of the message
- %t - The name of the logging thread
- %d(FORMAT) - A timestamp, formatted with FORMAT.
The datetime FORMAT is a UNIX style format string detailed in Data.Time.Format. The only difference is that closing brackets ')' inside the datetime format must be escaped with a backslash.
Example:
logFormat = $(format "%d(%T) (%s) %t: %m")
Which when logging with
will produce something like:
logI
"Something"
14:49:06 (INFO ) main: Something
Example for escaping ')' in the datetime format string:
logFormat = $(format "%d((%F\\)(%T\\)) %m")
Which when logging with
will produce:
logI
"Something"
(2013-10-02)(16:26:21) Something
Note how we need an additional '\' because of Haskell strings
- data FormatElem
- = MessageElem
- | SeverityElem
- | StringElem Text
- | DateTimeElem (ZonedTime -> Text)
- | ThreadElem
- type Format = [FormatElem]
- format :: String -> ExpQ
Format
data FormatElem Source
A FormatElem
is a formatting element
type Format = [FormatElem]Source
Format
is the type of a full format. It is simply a list of FormatElem
s