You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 impure 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 something along the lines of:
40
+
```
41
+
ConsoleLogger(stream, min_level) =
42
+
MinLevelLogger(
43
+
ActiveFilteredLogger(max_log_filter,
44
+
PureConsoleLogger(stream)
45
+
),
46
+
min_level
47
+
)
48
+
```
49
+
9
50
10
-
##Usage
51
+
# Usage
11
52
Load the package with `using LoggingExtras`.
12
53
You likely also want to load the `Logging` standard lib.
13
54
Loggers can be constructed and used like normal.
@@ -19,7 +60,7 @@ For full details, see the [Julia documentation on Logging](https://docs.julialan
19
60
To use a `logger` in a given scope do
20
61
```
21
62
with_logger(logger) do
22
-
#things
63
+
#things
23
64
end
24
65
```
25
66
@@ -34,56 +75,62 @@ logger = global_logger()
34
75
```
35
76
36
77
# Loggers introduced by this package:
37
-
38
-
39
-
This package introduces 3 new loggers.
40
-
The `DemuxLogger`, the `FilteredLogger` and the `FileLogger`.
78
+
This package introduces 6 new loggers.
79
+
The `DemuxLogger`, the `TransformerLogger`, 3 types of filtered logger, and the `FileLogger`.
41
80
All of them just wrap existing loggers.
42
-
The `DemuxLogger` sends the logs to multiple different loggers.
43
-
The `FilteredLogger` lets you add rules to cause a logger to ignore some inputs.
81
+
- The `DemuxLogger` sends the logs to multiple different loggers.
82
+
- The `TransformerLogger` applies a function to modify log messages before passing them on.
83
+
- The 3 filter loggers are used to control if a message is written or not
84
+
- The `MinLevelLogger` only allowes messages to pass that are above a given level of severity
85
+
- The `EarlyFilteredLogger` lets you write filter rules based on the `level`, `module`, `group` and `id` of the log message
86
+
- The `ActiveFilteredLogger` lets you filter based on the full content
87
+
- The `FileLogger` is a simple logger sink that writes to file.
44
88
89
+
By combining `DemuxLogger` with filter loggers you can arbitrarily route log messages, wherever you want.
45
90
46
-
By combining `DemuxLogger` with `FilteredLogger`s you can arbitrarily route log messages, wherever you want.
47
91
48
-
The `FileLogger` is just a convience wrapper around the base julia `SimpleLogger`,
49
-
to make it easier to pass in a filename, rather than a stream.
50
-
51
-
52
-
## `DemuxLogger` and `FileLogger`
92
+
## `DemuxLogger`
53
93
54
94
The `DemuxLogger` sends the log messages to multiple places.
55
95
It takes a list of loggers.
56
96
It also has the keyword argument `include_current_global`,
57
97
to determine if you also want to log to the global logger.
58
98
59
-
It is up to those loggers to determine if they will accept it.\
99
+
It is up to those loggers to determine if they will accept it.
60
100
Which they do using their methods for `shouldlog` and `min_enabled_level`.
61
-
Or you can do, by wrapping them in a `FilteredLogger` as discussed below.
101
+
Or you can do, by wrapping them in a filtered logger as discussed below.
62
102
103
+
## `FileLogger`
63
104
The `FileLogger` does logging to file.
105
+
It is just a convience wrapper around the base julia `SimpleLogger`,
106
+
to make it easier to pass in a filename, rather than a stream.
64
107
It is really simple.
65
-
It takes a filename; and the minimum level it should log.
108
+
- It takes a filename,
109
+
- a kwarg to check if should `always_flush` (default: `true`).
110
+
- a kwarg to `append` rather than overwrite (default `false`. i.e. overwrite by default)
111
+
The resulting file format is similar to that which is shown in the REPL.
0 commit comments