Skip to content
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

Variables not properly escaped inside logging macros #48015

Closed
simonbyrne opened this issue Dec 28, 2022 · 1 comment
Closed

Variables not properly escaped inside logging macros #48015

simonbyrne opened this issue Dec 28, 2022 · 1 comment
Labels
logging The logging framework

Comments

@simonbyrne
Copy link
Contributor

A couple of weird cases I found:

  1. level:
julia> using Logging

julia> macro log_level()
           quote
               level = Logging.Info
               Logging.@logmsg level "message"
           end
       end
@log_level (macro with 1 method)

julia> @log_level
ERROR: UndefVarError: `level` not defined
Stacktrace:
 [1] macro expansion
   @ logging.jl:371 [inlined]
 [2] top-level scope
   @ REPL[2]:4

If I rename the variable level, it works as intended

  1. msg
julia> using Logging

julia> macro log_msg()
           quote
               msg = "message"
               Logging.@info msg
           end
       end
@log_msg (macro with 1 method)

julia> @log_msg
┌ Error: Exception while generating log record in module Main at REPL[8]:4
│   exception =
│    UndefVarError: `msg` not defined
│    Stacktrace:
│      [1] backtrace()
│        @ Base ./error.jl:114
│      [2] logging_error(logger::Any, level::Any, _module::Any, group::Any, id::Any, filepath::Any, line::Any, err::Any, real::Bool)
│        @ Base.CoreLogging ./logging.jl:465
│      [3] macro expansion
│        @ logging.jl:352 [inlined]
│      [4] top-level scope
│        @ REPL[8]:4
│      [5] eval
│        @ ./boot.jl:370 [inlined]
│      [6] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
│        @ REPL /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:152
│      [7] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
│        @ REPL /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:248
│      [8] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
│        @ REPL /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:233
│      [9] start_repl_backend
│        @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:230 [inlined]
│     [10] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
│        @ REPL /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:376
│     [11] run_repl(repl::REPL.AbstractREPL, consumer::Any)
│        @ REPL /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/REPL.jl:362
│     [12] (::Base.var"#1016#1018"{Bool, Bool, Bool})(REPL::Module)
│        @ Base ./client.jl:421
│     [13] #invokelatest#2
│        @ ./essentials.jl:816 [inlined]
│     [14] invokelatest
│        @ ./essentials.jl:813 [inlined]
│     [15] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
│        @ Base ./client.jl:405
│     [16] exec_options(opts::Base.JLOptions)
│        @ Base ./client.jl:322
│     [17] _start()
│        @ Base ./client.jl:522
└ @ Main REPL[8]:4

Again, renaming the variable msg it works as intended.

@simonbyrne simonbyrne added the logging The logging framework label Dec 28, 2022
@giordano
Copy link
Contributor

Duplicate of #41451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging The logging framework
Projects
None yet
Development

No branches or pull requests

2 participants