Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module extends extends the di logging ecosystem with support for the df1 hierarchical structured logging format.
Particularly, it exports df1
for rendering df1-formatted logs, an
extension to the Di.Core API with vocabulary specific to df1, and
functions like fromDiLog
or fromDf1Log
to convert back and forth between
di and df1 types.
The Di.Df1.Monad module belonging to this same package exports an extension to the Di.Monad API, rather than to Di.Core.
Consider this a preview release: The API is likely to stay stable, but extensive testing, formalization and tooling is due.
Synopsis
- type Df1 = Di Level Path Message
- push :: Segment -> Di level Path msg -> Di level Path msg
- attr :: ToValue value => Key -> value -> Di level Path msg -> Di level Path msg
- attr_ :: Key -> Value -> Di level Path msg -> Di level Path msg
- debug :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- info :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- notice :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- warning :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- error :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- alert :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- critical :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- emergency :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m ()
- debug_ :: MonadIO m => Di Level path Message -> Message -> m ()
- info_ :: MonadIO m => Di Level path Message -> Message -> m ()
- notice_ :: MonadIO m => Di Level path Message -> Message -> m ()
- warning_ :: MonadIO m => Di Level path Message -> Message -> m ()
- error_ :: MonadIO m => Di Level path Message -> Message -> m ()
- alert_ :: MonadIO m => Di Level path Message -> Message -> m ()
- critical_ :: MonadIO m => Di Level path Message -> Message -> m ()
- emergency_ :: MonadIO m => Di Level path Message -> Message -> m ()
- debug' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- info' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- notice' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- warning' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- error' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- alert' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- critical' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- emergency' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m ()
- df1 :: LineRenderer Level Path Message
- fromDiLog :: Log Level Path Message -> Log
- fromDf1Log :: Log -> Log Level Path Message
- data Level
- data Path
- data Segment
- class ToSegment a where
- data Key
- class ToKey a where
- data Value
- class ToValue a where
- data Message
- class ToMessage a where
Documentation
type Df1 = Di Level Path Message Source #
Convenience type-synonym for a Di
restricted to all the df1
monomorphic types.
Df1
==Di
Level
Path
Message
:: *
This type-synonym is not used within the di-df1
library itself because
all functions exposed in the library have more general types. However,
users are encouraged to use Df1
if they find it useful to reduce
boilerplate and improve type inference.
Hierarchy
Metadata
Logging from IO
debug :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a message intended to be useful only when deliberately debugging a program.
info :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log an informational message.
notice :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a condition that is not an error, but should possibly be handled specially.
warning :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a warning condition, such as an exception being gracefully handled or some missing configuration setting being assigned a default value.
error :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log an error condition, such as an unhandled exception.
alert :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a condition that should be corrected immediately, such as a corrupted database.
critical :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a critical condition that could result in system failure, such as a disk running out of space.
emergency :: (MonadIO m, ToMessage msg) => Di Level path Message -> msg -> m () Source #
Log a message stating that the system is unusable.
Type-inference helpers
Logging from STM
debug' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
info' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
notice' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
warning' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
error' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
alert' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
critical' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
emergency' :: (Monad m, ToMessage msg) => (forall x. STM x -> m x) -> Di Level path Message -> msg -> m () Source #
Support for Di.Handle
Conversion
fromDiLog :: Log Level Path Message -> Log Source #
Convert a Log
from Df1 to a Log
from Di.Core.
fromDiLog
.fromDf1Log
==id
fromDf1Log
.fromDiLog
==id
fromDf1Log :: Log -> Log Level Path Message Source #
Convert a Log
from Di.Core to a Log
from Df1.
fromDiLog
.fromDf1Log
==id
fromDf1Log
.fromDiLog
==id
Types from Df1
Importance of the logged message.
These levels, listed in increasing order of importance, correspond to the levels used by syslog(3).
Path
represents the hierarchical structure of logged messages.
For example, consider a df1 log line as like the following:
1999-12-20T07:11:39.230553031Z /foo x=a y=b /bar /qux z=c z=d WARNING Something
For that line, the log_path
attribute of the Log
datatype will contain
the following:
[Push
(segment
"foo") ,Attr
(key
"x") (value
"a") ,Attr
(key
"y") (value
"b") ,Push
(segment
"bar") ,Push
(segment
"qux") ,Attr
(key
"z") (value
"c") ,Attr
(key
"z") (value
"d") ] ::Seq
Path
Please notice that [] ::
is a valid path insofar as df1
is concerned, and that Seq
Path
Attr
and Push
can be juxtapositioned in any order.
A path segment.
If you have the OverloadedStrings
GHC extension enabled, you can build a
Segment
using a string literal:
"foo" :: Segment
Otherwise, you can use fromString
or segment
.
Notice that "" ::
is acceptable, and will be correctly rendered
and parsed back.Segment
Convert an arbitrary type to a Segment
.
You are encouraged to create custom ToSegment
instances for your types
making sure you avoid rendering sensitive details such as passwords, so that
they don't accidentally end up in logs.
Any characters that need to be escaped for rendering will be automatically escaped at rendering time. You don't need to escape them here.
An attribute key (see Attr
).
If you have the OverloadedStrings
GHC extension enabled, you can build a
Key
using a string literal:
"foo" :: Key
Otherwise, you can use fromString
or key
.
Notice that "" ::
is acceptable, and will be correctly rendered and
parsed back.Key
Convert an arbitrary type to a Key
.
You are encouraged to create custom ToKey
instances for your types
making sure you avoid rendering sensitive details such as passwords, so that
they don't accidentally end up in logs.
Any characters that need to be escaped for rendering will be automatically escaped at rendering time. You don't need to escape them here.
An attribute value (see Attr
).
If you have the OverloadedStrings
GHC extension enabled, you can build a
Value
using a string literal:
"foo" :: Value
Otherwise, you can use fromString
or value
.
Notice that "" ::
is acceptable, and will be correctly rendered
and parsed back.Value
Convert an arbitrary type to a Value
.
You are encouraged to create custom ToValue
instances for your types
making sure you avoid rendering sensitive details such as passwords, so that
they don't accidentally end up in logs.
Any characters that need to be escaped for rendering will be automatically escaped at rendering time. You don't need to escape them here.
Instances
ToValue Bool | |
ToValue Double | |
ToValue Float | |
ToValue Int | |
ToValue Int8 | |
ToValue Int16 | |
ToValue Int32 | |
ToValue Int64 | |
ToValue Integer | |
ToValue Natural | |
ToValue Word | |
ToValue Word8 | |
ToValue Word16 | |
ToValue Word32 | |
ToValue Word64 | |
ToValue Text | x :: |
ToValue Text | x :: |
ToValue String | x :: |
ToValue SomeException | |
Defined in Df1.Types value :: SomeException -> Value # | |
ToValue Value | Identity. |
A message text.
If you have the OverloadedStrings
GHC extension enabled, you can build a
Message
using a string literal:
"foo" :: Message
Otherwise, you can use fromString
or message
.
Notice that "" ::
is acceptable, and will be correctly rendered
and parsed back.Message
Convert an arbitrary type to a Message
.
You are encouraged to create custom ToMessage
instances for your types
making sure you avoid rendering sensitive details such as passwords, so that
they don't accidentally end up in logs.
Any characters that need to be escaped for rendering will be automatically escaped at rendering time. You don't need to escape them here.