Skip to content

Commit c0b6afb

Browse files
authored
Allow expressions as logging keys (#37036)
These will be converted to Symbols, similar to how positional args are handled
1 parent 31d7210 commit c0b6afb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

base/logging.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ function process_logmsg_exs(_orig_module, _file, _line, level, message, exs...)
314314
_module = _orig_module
315315
kwargs = Any[]
316316
for ex in exs
317-
if ex isa Expr && ex.head === :(=) && ex.args[1] isa Symbol
317+
if ex isa Expr && ex.head === :(=)
318318
k,v = ex.args
319319
if !(k isa Symbol)
320-
throw(ArgumentError("Expected symbol for key in key value pair `$ex`"))
320+
k = Symbol(k)
321321
end
322322

323323
# Recognize several special keyword arguments

test/logging.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444
foo_val = 10
4545
bar_val = 100
4646
logs,_ = collect_test_logs() do
47-
@info "test" bar_val progress=0.1 foo=foo_val 2*3 real_line=(@__LINE__)
47+
@info "test" bar_val progress=0.1 foo=foo_val 2*3 bar(x)=1.2 real_line=(@__LINE__)
4848
@info begin
4949
value_in_msg_block = 1000.0
5050
"test2"
@@ -69,6 +69,7 @@ end
6969
@test kwargs[:progress] == 0.1
7070
@test kwargs[:foo] === foo_val
7171
@test kwargs[Symbol(:(2*3))] === 6
72+
@test kwargs[Symbol(:(bar(x)))] === 1.2
7273

7374
# Keyword values accessible from message block
7475
record2 = logs[2]

0 commit comments

Comments
 (0)