Skip to content

Commit dec3856

Browse files
DrviRAI CI (GitHub Action Automation)
authored andcommitted
RAI: Don't use macros inside logmsg_code (#250)
1 parent 071e2f9 commit dec3856

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

base/logging/logging.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,13 @@ end
347347
# Generate code for logging macros
348348
function logmsg_code(_module, file, line, level, message, exs...)
349349
@nospecialize
350+
msg = gensym(:msg)
351+
kwargs = gensym(:kwargs)
350352
log_data = process_logmsg_exs(_module, file, line, level, message, exs...)
351353
if !isa(message, Symbol) && issimple(message) && isempty(log_data.kwargs)
352354
logrecord = quote
353-
msg = $(message)
354-
kwargs = (;)
355+
$(msg) = $(message)
356+
$(kwargs) = (;)
355357
true
356358
end
357359
elseif issimple(message) && all(issimplekw, log_data.kwargs)
@@ -370,8 +372,8 @@ function logmsg_code(_module, file, line, level, message, exs...)
370372
logrecord = quote
371373
let err = $checkerrors
372374
if err === nothing
373-
msg = $(message)
374-
kwargs = (;$(log_data.kwargs...))
375+
$(msg) = $(message)
376+
$(kwargs) = (;$(log_data.kwargs...))
375377
true
376378
else
377379
@invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, false)
@@ -382,8 +384,8 @@ function logmsg_code(_module, file, line, level, message, exs...)
382384
else
383385
logrecord = quote
384386
try
385-
msg = $(esc(message))
386-
kwargs = (;$(log_data.kwargs...))
387+
$(msg) = $(esc(message))
388+
$(kwargs) = (;$(log_data.kwargs...))
387389
true
388390
catch err
389391
@invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, true)
@@ -410,13 +412,13 @@ function logmsg_code(_module, file, line, level, message, exs...)
410412
file = Base.fixup_stdlib_path(file)
411413
end
412414
line = $(log_data._line)
413-
local msg, kwargs
415+
local $(msg), $(kwargs)
414416
if $(logrecord)
415-
@assert @isdefined(msg) "Assertion to tell the compiler about the definedness of this variable"
416-
@assert @isdefined(kwargs) "Assertion to tell the compiler about the definedness of this variable"
417+
$(Expr(:isdefined, msg)) || throw(AssertionError("Assertion to tell the compiler about the definedness of this variable"))
418+
$(Expr(:isdefined, kwargs)) || throw(AssertionError("Assertion to tell the compiler about the definedness of this variable"))
417419
$handle_message_nothrow(
418-
logger, level, msg, _module, group, id, file, line;
419-
kwargs...)
420+
logger, level, $(msg), _module, group, id, file, line;
421+
$(kwargs)...)
420422
end
421423
end
422424
end

0 commit comments

Comments
 (0)