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
Copy file name to clipboardExpand all lines: README.md
+67-68Lines changed: 67 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,9 @@
8
8
9
9
# Discussion: Compositional Loggers
10
10
11
-
When constructing complicated "log plumbing" systems, LoggingExtras allows for routing logged information to different places. Built upon the concept of simple parts composed together, LoggingExtras provides a powerful and flexible definition of your logging system without a need to define any custom loggers by subtyping `AbstractLogger`.
12
-
When we talk about composability, the composition of any set of Loggers is itself a Logger, and LoggingExtras is a composable logging system.
11
+
LoggingExtras allows routing logged information to different places when constructing complicated "log plumbing" systems. Built upon the concept of simple parts composed together, subtyping `AbstractLogger` provides a powerful and flexible definition for your logging system without a need to define any custom loggers. When we talk about composability, the composition of any set of Loggers is itself a Logger, and LoggingExtras is a composable logging system.
13
12
14
-
Loggers can be broken down into 4 types:
13
+
Loggers break down into four types:
15
14
-*Sinks*: Sinks are the endpoint of a log message 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.
16
15
-*Filters*: Filters wrap around other loggers and decide whether or not to pass on a message. When that decision occurs, they can be further broken down (See `ActiveFilteredLogger` vs `EarlyFilteredLogger`).
17
16
-*Transformers*: Transformers modify the content of log messages before passing them on, including metadata, such as severity level. Unlike Filters, they can't block a log message, but they could drop its level down to say Debug so that usually no one would see it.
@@ -21,7 +20,7 @@ This is a complete taxonomy of all compositional loggers, with this package impl
21
20
22
21
It is worth understanding the idea of logging purity. The loggers defined in this package are all pure. The Filters only filter, the Sinks only sink, and the transformers only Transform.
23
22
24
-
We can contrast this to the `ConsoleLogger` (the standard logger in the REPL). The `ConsoleLogger` is an impure sink. As well as displaying logs to the user (as a Sink); it uses the log content, in the form of the `max_log` to decide if a log should be displayed (Active Filtering); and it has a min_enabled_level setting, that controls if it will accept a message at all (Early Filtering, in particular see `MinLevelLogger`).
23
+
We can contrast this to the `ConsoleLogger` (the standard logger in the REPL). The `ConsoleLogger` is an impure sink. As well as displaying logs to the user (as a Sink); it uses the log content, in the form of the `max_log`, to decide whether to display a log (Active Filtering); and it has a min_enabled_level setting that controls if it will accept a message at all (Early Filtering, in particular, see `MinLevelLogger`).
25
24
If defined in a compositional way, we would write something along the lines of:
The user implicitly controls when the files will be rolled over based on the `DateFormat` given.
332
-
To post-process the newly rotated file pass `rotation_callback::Function` as a keyword argument.
329
+
The user implicitly controls when the files are rolled over based on the `DateFormat` given.
330
+
To post-process the newly rotated file, pass `rotation_callback::Function` as a keyword argument.
333
331
See the docstring with (`?DatetimeRotatingFileLogger` in the REPL) for more details.
334
332
335
-
To control the logging output it is possible to pass a formatter function as the first argument
336
-
in the constructor. See `FormatLogger` for the requirements on the formatter function.
333
+
To control the logging output, passing a formatter function as the first argument in the constructor
334
+
is possible. See FormatLogger for the requirements on the formatter function.
337
335
338
336
## `FormatLogger` (*Sink*)
339
-
The `FormatLogger` is a sink that formats the message and prints to a wrapped IO.
340
-
Formatting is done by providing a function `f(io::IO, log_args::NamedTuple)`.
337
+
The `FormatLogger` is a sink that formats the message and prints it to a wrapped IO
338
+
with formatting provided by providing a function `f(io::IO, log_args::NamedTuple)`.
341
339
342
-
`FormatLogger` can take as its second argument either a writeable `IO` or a filepath. The `append::Bool` keyword
343
-
argument determines whether the file is opened in append mode (`"a"`) or truncate mode (`"w"`).
340
+
`FormatLogger` can take either a writeable `IO` or a filepath as its second argument. The `append::Bool` keyword
341
+
argument determines whether to open the file in append mode (`"a"`) or truncate mode (`"w"`).
344
342
345
343
```julia
346
344
julia>using LoggingExtras
@@ -364,9 +362,10 @@ Main | [Warn] This is a warning, should take a look.
364
362
## `LevelOverrideLogger` (*Filter*)
365
363
Allows overriding the minimum log level set by the logger it wraps.
366
364
Useful when debug logging
367
-
and used in conjuction with `Logging.with_logger` or `LoggingExtras.withlevel` to
365
+
and used in conjunction with `Logging.with_logger` or `LoggingExtras.withlevel` to
368
366
temporarily modify the current logger with a custom level.
369
-
More generally useful if you want to use the current/global logger as a _sink_ but don't know if it is going to have a problematically high min log level set (as julia's default logger sets min level to `Info`).
367
+
More generally applicable if you want to use the current/global logger as a _sink_
368
+
but don't know if it will have a problematically high min log level set (as julia's default logger sets min level to `Info`).
370
369
371
370
```julia
372
371
julia>using LoggingExtras
@@ -381,24 +380,24 @@ julia> with_logger(logger) do
381
380
```
382
381
This is roughly complementary to the `MinLevelFilterLogger`.
383
382
The `MinLevelFilterLogger` lets you effectively *raise* the level of any logger it wraps to meet the level you specify.
384
-
The `LevelOverrideLogger` lets you *lower* (or *raise*) the level of the wrapped logger as it bypasses checks on it entirely.
383
+
The `LevelOverrideLogger` enables you to *lower* (or *raise*) the level of the wrapped logger as it bypasses checks on it entirely.
385
384
386
385
# Utilities
387
386
388
387
## Verbosity macros
389
-
Sometimes when logging, it is desirable to be able to specify a verbosity level along with
390
-
the log level, and to be able to filter on verbosity levels. For example, you may want multiple levels
391
-
of verbosity for `Debug` log statements. LoggingExtras.jl exports verbosity macros that act like their
392
-
non-verbose counterparts, but allow specifying a verbosity level as well:
388
+
Sometimes when logging, it is desirable to specify a verbosity level along with
389
+
the log level and to be able to filter on verbosity levels. For example, you may want multiple
390
+
verbosity levels for `Debug` log statements. LoggingExtras.jl exports verbosity macros that act like their
391
+
non-verbose counterparts but allow specifying a verbosity level as well:
393
392
* `@debugv N msg`
394
393
* `@infov N msg`
395
394
* `@warnv N msg`
396
395
* `@errorv N msg`
397
396
398
-
For verbosity filtering, the `LoggingExtras.withlevel(f, Info; verbosity=0)` utlility is provided
399
-
for temporarily (i.e. while `f()` is executed) allowing log messages with `level` and `verbosity`.
400
-
This is very handy for allowing finergrained control in debug logging for long-running or complex user API function
401
-
calls. For example:
397
+
For verbosity filtering, the `LoggingExtras.withlevel(f, Info; verbosity=0)` utility is provided,
398
+
temporarily (i.e. while `f()` is executed) allowing log messages with `level` and `verbosity`.
399
+
This is very handy for allowing finer-grained debug logging control for long-running or complex user API function calls.
0 commit comments