Skip to content

Commit ee26f66

Browse files
committed
Add Discussion to readme
1 parent 4a6e10d commit ee26f66

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,50 @@
66

77
![Diagram showing how loggers connect](diag.svg)
88

9+
# Discussion: Compositional Loggers
10+
11+
LoggingExtras is designs around allowing you to build arbitrarily complicated
12+
systems for "log plumbing". That is to say basically routing logged information to different places.
13+
It is built around the idea of simple parts which are composed together,
14+
to allow for powerful and flexible definition of your logging system.
15+
Without having to define any custom loggers by subtyping `AbstractLogger`.
16+
When we talk about composability we mean to say that the composition of any set of Loggers is itself a Logger.
17+
LoggingExtras is a composable logging system.
18+
19+
Loggers can be broken down into 4 types:
20+
- *Sinks*: Sinks are the final end point of a log messages journey. They write it to file, or display it on the console, or set off a red flashing light in the laboratory. A Sink should never decide what to accept, only what to do with it.
21+
- *Filters*: Filters wrap around other loggers and decide wether or not to pass on a message. Thery can further be broken down by when that decision occurs (See `ActiveFilteredLogger` vs `EarlyFilteredLogger`).
22+
- *Transformers*: Transformers modify the content of log messages, before passing them on. This includes the metadata like severity level. Unlike Filters they can't block a log message, but they could drop its level down to say `Debug` so that normally noone would see it.
23+
- *Demux*: There is only one possible Demux Logger. and it is central to log routing. It acts as a hub that recieves 1 log message, and then sends copies of it to all its child loggers. Like iin the diagram above, it can be composed with Filters to control what goes where.
24+
25+
This is a basically full taxonomy of all compositional loggers.
26+
Other than `Sinks`, this package implements the full set. So you shouldn't need to build your own routing components, just configure the ones included in this package.
27+
28+
It is worth understanding the idea of logging purity.
29+
The loggers defined in this package are all pure.
30+
The Filters, only filter, the Sinks only sink, the transformers only Transform.
31+
32+
We can contrast this to the the `ConsoleLogger` (the standard logger in the REPL).
33+
The `ConsoleLogger` is an in-pure sink.
34+
As well as displaying logs to the user (as a Sink);
35+
it uses the log content, in the form of the `max_log` kwarg to decide if a log should be displayed (Active Filtering);
36+
and it has a min_enabled_level setting, that controls if it will accept a message at all
37+
(Early Filtering, in particular see `MinLevelLogger`).
38+
If it was to be defined in a compositional way,
39+
we would write;
40+
```
41+
42+
const ConsoleLogger(stream, min_level) =
43+
MinLevelLogger(
44+
ActiveFilteredLogger(max_log_filter,
45+
PureConsoleLogger(stream)
46+
),
47+
min_level
48+
)
49+
```
950

10-
## Usage
51+
52+
# Usage
1153
Load the package with `using LoggingExtras`.
1254
You likely also want to load the `Logging` standard lib.
1355
Loggers can be constructed and used like normal.
@@ -277,3 +319,4 @@ end
277319
global_logger(transformer_logger)
278320
```
279321

322+

0 commit comments

Comments
 (0)