Logging2.jl

Logging2.LineBufferedIOType
LineBufferedIO(dest::IO)

A thread safe line buffered IO wrapper which buffers writes until a full line (delimited by '\n') is received. Full lines are written to the downstream dest IO.

To ensure that the tail of the stream is written (even without a trailing '\n'), be sure to call close().

Logging2.LoggingStreamType
LoggingStream(logger; level, id)

An IO object which collects incoming calls to write and writes them to the Julia logging system via logger. Most useful when combined with LineBufferedIO. The standard logging _id field will be set to id.

Base.redirect_stderrFunction
redirect_stderr(f::Function, logger::AbstractLogger)

Redirect the global stderr stream to logger, with each line becoming a log event during the execution of the function f.

See redirect_stdout for examples and additional information.

Base.redirect_stdoutFunction
redirect_stdout(f::Function, logger::AbstractLogger)

Redirect the global stdout stream to logger, with each line becoming a log event during the execution of the function f.

Note

In contrast to the dynamic scope of the usual logging system frontend (@info, etc), stdout is a global object so it's not entirely clear that we can collect the logger from the current dynamic scope where Base.stdout is looked up, and efficiently use it.

In particular, some particular uses of stdout require it to have an operating system primitive like a Pipe backing the object. However not all uses require this, and it may be possible to improve the situation in the future.

Examples

Here's how you use redirect_stdout in structured concurrency style:

redirect_stdout(current_logger()) do
    println("Hi")
    run(`ls`)
end