0 | ||| The fundamental LogAction type and combinators.
1 | |||
2 | ||| A `LogAction m msg` is a first-class logging value: a function that
3 | ||| consumes a message of type `msg` in some monadic context `m`.
4 | ||| LogActions compose via Semigroup (fan-out to multiple destinations),
5 | ||| transform via Contravariant (adapt message types), and filter via
6 | ||| predicates.
13 | ----------------------------------------------------------------------
14 | -- Core type
15 | ----------------------------------------------------------------------
17 | ||| A logging action that consumes messages of type `msg` in context `m`.
18 | |||
19 | ||| This is the central type of log4types. A LogAction is a first-class
20 | ||| value that can be composed, transformed, and passed around.
26 | ----------------------------------------------------------------------
27 | -- Execution
28 | ----------------------------------------------------------------------
33 | ||| Execute a log action on a message.
34 | |||
35 | ||| ```idris
36 | ||| logStringStdout <& "hello"
37 | ||| ```
42 | ||| Execute a log action on a message (flipped).
47 | ----------------------------------------------------------------------
48 | -- Contravariant
49 | ----------------------------------------------------------------------
51 | ||| Transform the message type before logging.
52 | |||
53 | ||| If you can log `b` and you have `a -> b`, you can log `a`.
62 | ||| Transform the message type using a monadic computation.
63 | |||
64 | ||| Like `cmap` but the transformation can perform effects.
65 | ||| Useful for enriching messages with timestamps, thread IDs, etc.
70 | ----------------------------------------------------------------------
71 | -- Composition
72 | ----------------------------------------------------------------------
74 | ||| Combine two log actions: both receive the same message.
79 | ||| The silent log action that discards all messages.
84 | ----------------------------------------------------------------------
85 | -- Filtering
86 | ----------------------------------------------------------------------
88 | ||| Only log messages satisfying a predicate.
94 | ||| Only log messages satisfying a monadic predicate.
101 | ||| Transform and filter: only log when the function returns Just.
109 | ----------------------------------------------------------------------
110 | -- Divisible
111 | ----------------------------------------------------------------------
113 | ||| Split a message into two parts and log each to a different action.
114 | |||
115 | ||| Contravariant analogue of Applicative: if you can split `a` into
116 | ||| `(b, c)` and log each independently, you can log `a`.
126 | ----------------------------------------------------------------------
127 | -- Decidable
128 | ----------------------------------------------------------------------
130 | ||| Route a message to one of two loggers based on a decision function.
131 | |||
132 | ||| Contravariant analogue of Alternative: if you can decide whether
133 | ||| `a` is a `b` or a `c`, and log each, you can log `a`.
145 | ----------------------------------------------------------------------
146 | -- Monad transformation
147 | ----------------------------------------------------------------------
149 | ||| Transform the monadic context of a LogAction via a natural transformation.