Logger
TanayLabUtilities.Logger
—
Module
Setup a global logger the way we like it.
TanayLabUtilities.Logger.setup_logger
—
Function
setup_logger(
io::IO = stderr;
[level::LogLevel = Info,
show_time::Bool = true,
show_module::Bool = true,
show_location::Bool = false]
)::Nothing
Setup a global logger that will print into
io
.
By default, this will only print warnings. Note that increasing the log level will apply to
everything
. An alternative is to set up the environment variable
JULIA_DEBUG
to a comma-separated list of modules you wish to see the debug messages of.
If
show_time
, each message will be prefixed with a
yyyy-dd-mm HH:MM:SS.sss
timestamp prefix.
If
show_module
, each message will be prefixed with the name of the module emitting the message.
If
show_location
, each message will be prefixed with the file name and the line number emitting the message.
When multi-processing is used, a
P<id>:
process index is added to the log entries. When multi-threading is used, a
T<id>:
thread index is added to the log entries, as well as a
K<id>:
task index. To generate the latter, this stores a unique
:task_id
index in the
task_local_storage
. This is important since a task may migrate between threads.
TanayLabUtilities.Logger.@logged
—
Macro
@logged function something(...)
return ...
end
Automatically log (in
Debug
level) every invocation to the function. This will also log the values of the arguments. Emits a second log entry when the function returns, with the result (if any).
@logged function bar()::Nothing
return nothing
end
@logged function foo(positional; named = 1 + 2)
bar()
return positional + named
end
using Logging
using Test
logger = TestLogger(; min_level = Logging.Debug)
with_logger(logger) do
return foo(1; named = 2)
end
print(join(["$(record.level) : $(record.message)" for record in logger.logs], "
"))
# output
Debug : foo {
Debug : - positional: 1
Debug : - named: 2
Debug : bar {
Debug : bar return }
Debug : foo return: 3 }