| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Control.Tracer.JSON
Description
Structured JSON logging over the
contra-tracer generic
logging framework. A Tracer acquired here wraps each message in an
Envelope carrying a timestamp, thread id and namespace, and writes it as
one JSON object per line.
Synopsis
- newtype Tracer (m :: Type -> Type) a = Tracer {
- runTracer :: a -> m ()
- natTracer :: (forall x. m x -> n x) -> Tracer m s -> Tracer n s
- nullTracer :: forall (m :: Type -> Type) a. Applicative m => Tracer m a
- traceWith :: Tracer m a -> a -> m ()
- contramap :: Contravariant f => (a' -> a) -> f a -> f a'
- data Verbosity
- data Envelope a = Envelope {}
- defaultLogBuffering :: BufferMode
- withTracer :: forall m msg a. (MonadIO m, MonadFork m, MonadTime m, ToJSON msg) => Verbosity -> (Tracer m msg -> IO a) -> IO a
- withTracerOutputTo :: forall m msg a. (MonadIO m, MonadFork m, MonadTime m, ToJSON msg) => BufferMode -> Handle -> Text -> (Tracer m msg -> IO a) -> IO a
- showLogsOnFailure :: (MonadLabelledSTM m, MonadCatch m, MonadFork m, MonadTime m, MonadSay m, ToJSON msg) => Text -> (Tracer m msg -> m a) -> m a
- traceInTVar :: (MonadFork m, MonadTime m, MonadSTM m) => TVar m [Envelope msg] -> Text -> Tracer m msg
- mkEnvelope :: (MonadFork m, MonadTime m) => Text -> msg -> m (Envelope msg)
- defaultQueueSize :: Natural
Tracer
newtype Tracer (m :: Type -> Type) a #
Instances
| Contravariant (Tracer m) | |
| Applicative m => Monoid (Tracer m s) | |
| Applicative m => Semigroup (Tracer m s) | |
nullTracer :: forall (m :: Type -> Type) a. Applicative m => Tracer m a #
contramap :: Contravariant f => (a' -> a) -> f a -> f a' Source #
Using it
Instances
| FromJSON Verbosity Source # | |
Defined in Control.Tracer.JSON | |
| ToJSON Verbosity Source # | |
Defined in Control.Tracer.JSON Methods toEncoding :: Verbosity -> Encoding toJSONList :: [Verbosity] -> Value toEncodingList :: [Verbosity] -> Encoding | |
| Generic Verbosity Source # | |
| Show Verbosity Source # | |
| Eq Verbosity Source # | |
| type Rep Verbosity Source # | |
Defined in Control.Tracer.JSON type Rep Verbosity = D1 ('MetaData "Verbosity" "Control.Tracer.JSON" "contra-tracer-json-0.1.0.0-Ehq1kqfRLHnFfpOzXYyzFl" 'False) (C1 ('MetaCons "Quiet" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Verbose" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) | |
Provides logging metadata for entries.
Instances
| ToJSON a => ToJSON (Envelope a) Source # | |
Defined in Control.Tracer.JSON Methods toEncoding :: Envelope a -> Encoding toJSONList :: [Envelope a] -> Value toEncodingList :: [Envelope a] -> Encoding | |
| Generic (Envelope a) Source # | |
| Show a => Show (Envelope a) Source # | |
| Eq a => Eq (Envelope a) Source # | |
| type Rep (Envelope a) Source # | |
Defined in Control.Tracer.JSON type Rep (Envelope a) = D1 ('MetaData "Envelope" "Control.Tracer.JSON" "contra-tracer-json-0.1.0.0-Ehq1kqfRLHnFfpOzXYyzFl" 'False) (C1 ('MetaCons "Envelope" 'PrefixI 'True) ((S1 ('MetaSel ('Just "timestamp") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTCTime) :*: S1 ('MetaSel ('Just "threadId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "namespace") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "message") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))) | |
defaultLogBuffering :: BufferMode Source #
Buffering used for log output. The writer batches whatever the queue holds and flushes each batch, so this bounds the syscalls rather than the latency.
withTracer :: forall m msg a. (MonadIO m, MonadFork m, MonadTime m, ToJSON msg) => Verbosity -> (Tracer m msg -> IO a) -> IO a Source #
withTracerOutputTo :: forall m msg a. (MonadIO m, MonadFork m, MonadTime m, ToJSON msg) => BufferMode -> Handle -> Text -> (Tracer m msg -> IO a) -> IO a Source #
showLogsOnFailure :: (MonadLabelledSTM m, MonadCatch m, MonadFork m, MonadTime m, MonadSay m, ToJSON msg) => Text -> (Tracer m msg -> m a) -> m a Source #
Capture logs and output them to stdout when an exception was raised by the
given action. This tracer is wrapping msg into an Envelope with
metadata.
traceInTVar :: (MonadFork m, MonadTime m, MonadSTM m) => TVar m [Envelope msg] -> Text -> Tracer m msg Source #
mkEnvelope :: (MonadFork m, MonadTime m) => Text -> msg -> m (Envelope msg) Source #