Logging2
Logging2 is a library which extends the standard Julia Logging library with additional functionality. The intent of this library is to consolidate some of the more useful "core" logging functionality from the wider Julia ecosystem, and serve as a staging area to improve the logging standard library itself.
How-To
Redirect stdout or stderr to the logging system
Use redirect_stdout
or redirect_stderr
to redirect all strings written to
stdout
or stderr
to any AbstractLogger
during the execution of a given
do
block:
logger = current_logger() # or construct one explicitly
redirect_stdout(logger) do
println("Hi")
run(`ls`)
end
Note that stdout
and stder
are global streams, so this logging choice
is made globally for the whole program. Therefore, you should probably only do
this at the top level of your application (certainly never in any library
code which you expect to run concurrently).
The Wider Julia Logging Ecosystem
As of mid-2020, here is a list of libraries from the Julia ecosystem which relate to the standard logging infrastructure.
First off, Base
exports the four logging frontend macros @debug
, @info
,
@warn
, @error
and the stdlib
Logging
library provides a
default logger backend ConsoleLogger
for some basic filtering and pretty
printing of log records in the terminal. It combines convenient but
non-composable features into a single logger type.
Frontend
ProgressLogging.jl
provides some convenient frontend macros including@progress
which makes it easy to emit log records tracking the progress of looping constructs.
Log Event routing and transformation
LoggingExtras.jl
provides generic log transformation, filtering and routing functionality. You can use this to mutate messages as they go through the chain, duplicate a stream of log records into multiple streams, discard messages based on a predicate, etc.
Sinks
TerminalLoggers.jl
is a library for advanced terminal-based pretty printing of log records, including fancy progress bars and markdown formatting.TensorBoardLogger.jl
can log structured numeric data to TensorBoard as a backend.LogRoller.jl
has a backend for rotating log files once they hit a size limit.Syslogging.jl
provides a- backend to direct logs to syslog.
LoggingExtras.jl
provides a simpleFileLogger
sink.
Configuration
LogCompose.jl
provides declarative logger configuration and an associated.toml
file format.