-
Notifications
You must be signed in to change notification settings - Fork 22
Deprecate verbosity macros (not compatible w/ juliac-compiled programs) #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
function restore_callsite_source_position!(expr, src) | ||
function restore_callsite_source_position!(m, expr, src) | ||
@assert expr.head == :escape | ||
@assert expr.args[1].head == :macrocall | ||
@assert expr.args[1].args[2] isa LineNumberNode | ||
|
@@ -7,7 +7,15 @@ function restore_callsite_source_position!(expr, src) | |
# Logging.jl macros; otherwise, they would always report this (verbosity.jl) | ||
# file as the logging callsite | ||
expr.args[1].args[2] = src | ||
return expr | ||
ex = quote | ||
LoggingExtras.deprecate_verbosity($(Meta.quot(m))) | ||
$expr | ||
end | ||
return ex | ||
end | ||
|
||
function deprecate_verbosity(m) | ||
Base.depwarn("Verbosity logging macros are deprecated as they are not compatible with juliac-compiled programs", m; force=true) | ||
end | ||
|
||
vlogmacrodocs = """ | ||
|
@@ -34,56 +42,57 @@ end | |
|
||
"$vlogmacrodocs" | ||
macro debugv(verbosity::Int, msg, exs...) | ||
return restore_callsite_source_position!( | ||
return restore_callsite_source_position!(:debugv, | ||
esc(:($Base.@debug $msg _group=$(Verbosity(verbosity)) $(exs...))), | ||
__source__, | ||
) | ||
end | ||
|
||
"$vlogmacrodocs" | ||
macro infov(verbosity::Int, msg, exs...) | ||
return restore_callsite_source_position!( | ||
return restore_callsite_source_position!(:infov, | ||
esc(:($Base.@info $msg _group=$(Verbosity(verbosity)) $(exs...))), | ||
__source__, | ||
) | ||
end | ||
|
||
"$vlogmacrodocs" | ||
macro warnv(verbosity::Int, msg, exs...) | ||
return restore_callsite_source_position!( | ||
return restore_callsite_source_position!(:warnv, | ||
esc(:($Base.@warn $msg _group=$(Verbosity(verbosity)) $(exs...))), | ||
__source__, | ||
) | ||
end | ||
|
||
"$vlogmacrodocs" | ||
macro errorv(verbosity::Int, msg, exs...) | ||
return restore_callsite_source_position!( | ||
return restore_callsite_source_position!(:errorv, | ||
esc(:($Base.@error $msg _group=$(Verbosity(verbosity)) $(exs...))), | ||
__source__, | ||
) | ||
end | ||
|
||
"$vlogmacrodocs" | ||
macro logmsgv(verbosity::Int, level, msg, exs...) | ||
return restore_callsite_source_position!( | ||
return restore_callsite_source_position!(:logmsgv, | ||
esc(:($Base.@logmsg $level $msg _group=$(Verbosity(verbosity)) $(exs...))), | ||
__source__, | ||
) | ||
end | ||
|
||
""" | ||
LoggingExtras.withlevel(f, level; verbosity::Integer=0) | ||
LoggingExtras.withlevel(f, level; verbosity::Integer=0, group::Union{Symbol, Nothing}=nothing) | ||
|
||
Convenience function like `Logging.with_logger` to temporarily wrap | ||
the current logger with a level filter while `f` is executed. | ||
That is, the current logger will still be used for actual logging, but | ||
log messages will first be checked that they meet the `level` | ||
log level before being passed on to be logged. | ||
|
||
For convenience, a `verbosity` keyword argument can be passed which also | ||
filters the "verbose logging" messages; see [`@debugv`](@ref), [`@infov`](@ref), | ||
[`@warnv`](@ref), [`@errorv`](@ref), and [`@logmsgv`](@ref). | ||
For convenience, a `group` keyword argument can be passed which also | ||
filters logging messages on the "group". By default, the group is the | ||
file name of the log macro call site, but can be overridden by passing | ||
the `_group` keyword argument to the logging macros. | ||
|
||
Comment on lines
+92
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not conviced thsi is better than just using
Maybe we should instead be adding a
if it really is too long There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's really the convenience of having it bundled with the withlevel function. It's so onerous remembering the incantation to get the logger, set it to the new one, and then on top remember the LoggingExtras machinery to early filter. Bundling that all up into |
||
!!! note | ||
|
||
|
@@ -95,11 +104,24 @@ filters the "verbose logging" messages; see [`@debugv`](@ref), [`@infov`](@ref), | |
For more control directly construct the logger you want by making use of | ||
[`LevelOverrideLogger`](@ref) and then use `with_logger` to make it active. | ||
""" | ||
function withlevel(f, level::Union{Int, LogLevel}=Info; verbosity::Integer=0) | ||
with_logger(EarlyFilteredLogger( | ||
args -> !(args.group isa Verbosity) || verbosity >= args.group.verbosity, | ||
propagate_level_override(level, current_logger())) | ||
) do | ||
f() | ||
function withlevel(f, level::Union{Int, LogLevel}=Info; verbosity::Integer=0, group::Union{Symbol, Nothing}=nothing) | ||
if verbosity > 0 | ||
deprecate_verbosity(:withlevel) | ||
end | ||
verbosity > 0 && group !== nothing && throw(ArgumentError("Cannot specify both verbosity and group")) | ||
if group === nothing | ||
with_logger(EarlyFilteredLogger( | ||
args -> !(args.group isa Verbosity) || verbosity >= args.group.verbosity, | ||
propagate_level_override(level, current_logger())) | ||
) do | ||
f() | ||
end | ||
else | ||
with_logger(EarlyFilteredLogger( | ||
args -> args.group === group, | ||
propagate_level_override(level, current_logger()) | ||
)) do | ||
f() | ||
end | ||
end | ||
end |
Uh oh!
There was an error while loading. Please reload this page.