Skip to content

Commit f25251e

Browse files
committed
Slighly restructure README to follow the diagram:
demux, filters, transformers, sinks. Also fix some typos in README.
1 parent 92cbdfd commit f25251e

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

README.md

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ LoggingExtras is a composable logging system.
1818

1919
Loggers can be broken down into 4 types:
2020
- *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`).
21+
- *Filters*: Filters wrap around other loggers and decide whether or not to pass on a message. They can further be broken down by when that decision occurs (See `ActiveFilteredLogger` vs `EarlyFilteredLogger`).
2222
- *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.
23+
- *Demux*: There is only one possible Demux Logger. and it is central to log routing. It acts as a hub that receives 1 log message, and then sends copies of it to all its child loggers. Like in the diagram above, it can be composed with Filters to control what goes where.
2424

2525
This is a basically full taxonomy of all compositional loggers.
2626
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.
@@ -86,19 +86,19 @@ The `TeeLogger`, the `TransformerLogger`, 3 types of filtered logger, the `FileL
8686
the `DatetimeRotatingFileLogger` and the `FormatLogger`.
8787
All of them, except `FormatLogger`, just wrap existing loggers.
8888
- The `TeeLogger` sends the logs to multiple different loggers.
89-
- The `TransformerLogger` applies a function to modify log messages before passing them on.
9089
- The 3 filter loggers are used to control if a message is written or not
91-
- The `MinLevelLogger` only allowes messages to pass that are above a given level of severity
90+
- The `MinLevelLogger` only allows messages to pass that are above a given level of severity
9291
- The `EarlyFilteredLogger` lets you write filter rules based on the `level`, `module`, `group` and `id` of the log message
9392
- The `ActiveFilteredLogger` lets you filter based on the full content
93+
- The `TransformerLogger` applies a function to modify log messages before passing them on.
9494
- The `FileLogger` is a simple logger sink that writes to file.
9595
- The `DatetimeRotatingFileLogger` is a logger sink that writes to file, rotating logs based upon a user-provided `DateFormat`.
9696
- The `FormatLogger` is a logger sink that simply formats the message and writes to the logger stream.
9797

9898
By combining `TeeLogger` with filter loggers you can arbitrarily route log messages, wherever you want.
9999

100100

101-
## `TeeLogger`
101+
## `TeeLogger` (*Demux*)
102102

103103
The `TeeLogger` sends the log messages to multiple places.
104104
It takes a list of loggers.
@@ -109,53 +109,7 @@ It is up to those loggers to determine if they will accept it.
109109
Which they do using their methods for `shouldlog` and `min_enabled_level`.
110110
Or you can do, by wrapping them in a filtered logger as discussed below.
111111

112-
## `FileLogger`
113-
The `FileLogger` does logging to file.
114-
It is just a convience wrapper around the base julia `SimpleLogger`,
115-
to make it easier to pass in a filename, rather than a stream.
116-
It is really simple.
117-
- It takes a filename,
118-
- a kwarg to check if should `always_flush` (default: `true`).
119-
- a kwarg to `append` rather than overwrite (default `false`. i.e. overwrite by default)
120-
The resulting file format is similar to that which is shown in the REPL.
121-
(Not identical, but similar)
122-
123-
### Demo: `TeeLogger` and `FileLogger`
124-
We are going to log info and above to one file,
125-
and warnings and above to another.
126-
127-
```julia
128-
julia> using Logging; using LoggingExtras;
129-
130-
julia> demux_logger = TeeLogger(
131-
MinLevelLogger(FileLogger("info.log"), Logging.Info),
132-
MinLevelLogger(FileLogger("warn.log"), Logging.Warn),
133-
);
134-
135-
136-
julia> with_logger(demux_logger) do
137-
@warn("It is bad")
138-
@info("normal stuff")
139-
@error("THE WORSE THING")
140-
@debug("it is chill")
141-
end
142-
143-
shell> cat warn.log
144-
┌ Warning: It is bad
145-
└ @ Main REPL[34]:2
146-
┌ Error: THE WORSE THING
147-
└ @ Main REPL[34]:4
148-
149-
shell> cat info.log
150-
┌ Warning: It is bad
151-
└ @ Main REPL[34]:2
152-
┌ Info: normal stuff
153-
└ @ Main REPL[34]:3
154-
┌ Error: THE WORSE THING
155-
└ @ Main REPL[34]:4
156-
```
157-
158-
## `ActiveFilteredLogger`
112+
## `ActiveFilteredLogger` (*Filter*)
159113

160114
The `ActiveFilteredLogger` exists to give more control over which messages should be logged.
161115
It warps any logger, and before sending messages to the logger to log,
@@ -185,7 +139,7 @@ end
185139
[ Info: Yo Dawg! it is all good
186140
```
187141
188-
## `EarlyFilteredLogger`
142+
## `EarlyFilteredLogger` (*Filter*)
189143
190144
The `EarlyFilteredLogger` is similar to the `ActiveFilteredLogger`,
191145
but it runs earlier in the logging pipeline.
@@ -235,7 +189,7 @@ end
235189
└ ii = 10
236190
```
237191
238-
## `MinLevelLogger`
192+
## `MinLevelLogger` (*Filter*)
239193
This is basically a special case of the early filtered logger,
240194
that just checks if the level of the message is above the level specified when it was created.
241195
@@ -255,12 +209,12 @@ julia> with_logger(error_only_logger) do
255209
└ @ Main REPL[18]:4
256210
```
257211
258-
## `TransformerLogger`
212+
## `TransformerLogger` (*Transformer*)
259213
The transformer logger allows for the modification of log messages.
260214
This modification includes such things as its log level, and content,
261215
and all the other arguments passed to `handle_message`.
262216
263-
When constructing a `TransformerLogger` you pass in a tranformation function,
217+
When constructing a `TransformerLogger` you pass in a transformation function,
264218
and a logger to be wrapped.
265219
The transformation function takes a named tuple containing all the log message fields,
266220
and should return a new modified named tuple.
@@ -293,7 +247,53 @@ It can also be used to do things such as change the log level of messages from a
293247
Or to set common properties for all log messages within the `with_logger` block,
294248
for example to set them all to the same `group`.
295249
296-
## `DatetimeRotatingFileLogger`
250+
## `FileLogger` (*Sink*)
251+
The `FileLogger` does logging to file.
252+
It is just a convenience wrapper around the base julia `SimpleLogger`,
253+
to make it easier to pass in a filename, rather than a stream.
254+
It is really simple.
255+
- It takes a filename,
256+
- a kwarg to check if should `always_flush` (default: `true`).
257+
- a kwarg to `append` rather than overwrite (default `false`. i.e. overwrite by default)
258+
The resulting file format is similar to that which is shown in the REPL.
259+
(Not identical, but similar)
260+
261+
### Demo: `TeeLogger` and `FileLogger`
262+
We are going to log info and above to one file,
263+
and warnings and above to another.
264+
265+
```julia
266+
julia> using Logging; using LoggingExtras;
267+
268+
julia> demux_logger = TeeLogger(
269+
MinLevelLogger(FileLogger("info.log"), Logging.Info),
270+
MinLevelLogger(FileLogger("warn.log"), Logging.Warn),
271+
);
272+
273+
274+
julia> with_logger(demux_logger) do
275+
@warn("It is bad")
276+
@info("normal stuff")
277+
@error("THE WORSE THING")
278+
@debug("it is chill")
279+
end
280+
281+
shell> cat warn.log
282+
┌ Warning: It is bad
283+
└ @ Main REPL[34]:2
284+
┌ Error: THE WORSE THING
285+
└ @ Main REPL[34]:4
286+
287+
shell> cat info.log
288+
┌ Warning: It is bad
289+
└ @ Main REPL[34]:2
290+
┌ Info: normal stuff
291+
└ @ Main REPL[34]:3
292+
┌ Error: THE WORSE THING
293+
└ @ Main REPL[34]:4
294+
```
295+
296+
## `DatetimeRotatingFileLogger` (*Sink*)
297297
Use this sink to rotate your logs based upon a given `DateFormat`, automatically closing one file and opening another
298298
when the `DateFormat` would change the filename. Note that if you wish to have static portions of your filename, you must
299299
escape them so they are not interpreted by the `DateFormat` code. Example:
@@ -317,7 +317,7 @@ julia> filter(f -> endswith(f, ".log"), readdir(pwd()))
317317
318318
The user implicitly controls when the files will be rolled over based on the `DateFormat` given.
319319
320-
## `FormatLogger`
320+
## `FormatLogger` (*Sink*)
321321
The `FormatLogger` is a sink that formats the message and prints to a wrapped IO.
322322
Formatting is done by providing a function `f(io::IO, log_args::NamedTuple)`.
323323
@@ -389,7 +389,7 @@ global_logger(transformer_logger)
389389
## Add timestamp to all logging
390390
391391
```julia
392-
using Logging, LoggingExtras, Dates
392+
using Logging, LoggingExtras, Dates
393393

394394
const date_format = "yyyy-mm-dd HH:MM:SS"
395395

@@ -400,7 +400,7 @@ end
400400
ConsoleLogger(stdout, Logging.Debug) |> timestamp_logger |> global_logger
401401
```
402402
403-
This will produce output similar to:
403+
This will produce output similar to:
404404
```julia
405405
[ Info: 2019-09-20 17:43:54 /es/update 200
406406
┌ Debug: 2019-09-20 18:03:25 Recompiling stale cache file /.julia/compiled/v1.2/TranslationsController.ji for TranslationsController [top-level]

0 commit comments

Comments
 (0)