Some utilies that can be useful in connection with the
Logging standard
library. Also exports all exported symbols from the Logging standard
library.
From the Julia REPL, execute
using Pkg
pkg"add https://github.com/GHTaarn/LoggingUtils.jl"or using FreeRegistry:
using Pkg
pkg"registry add https://github.com/GHTaarn/FreeRegistry"
pkg"add LoggingUtils"There are two entry points, @no_logging and @with_logger which are both
described more precisely in their docstrings.
using LoggingUtils
function verbose_sin(x)
@info "calculating sin"
sin(x)
end
@no_logging println(verbose_sin(8))
mylogger = SimpleLogger()
@with_logger mylogger println(verbose_sin(8))Illustrating that @no_logging suppresses logging, whereas @with_logger
redirects logging to the specified logger.
Both @no_logging and @with_logger use the
Logging.with_logger
function internally and therefore assignments must be done externally, e.g.
using LoggingUtils
function verbose_sin(x)
@info "calculating sin"
sin(x)
end
a = @no_logging verbose_sin(1)
@assert a == sin(1)
@no_logging a = verbose_sin(2)
@assert a == sin(2)where the first assertion would pass and the second would fail.