Skip to content

Commit 7a45af6

Browse files
authored
Prevent invalidations of safe logging functionality by custom loggers. (#432)
1 parent 7c4855e commit 7a45af6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ using Logging
4343

4444
const STDERR_HAS_COLOR = Ref{Bool}(false)
4545

46+
# Prevent invalidation when packages define custom loggers
47+
# Using invoke in combination with @nospecialize eliminates backedges to these methods
48+
function _invoked_min_enabled_level(@nospecialize(logger))
49+
return invoke(Logging.min_enabled_level, Tuple{typeof(logger)}, logger)::LogLevel
50+
end
51+
4652
# define safe loggers for use in generated functions (where task switches are not allowed)
4753
for level in [:debug, :info, :warn, :error]
4854
@eval begin
@@ -53,7 +59,7 @@ for level in [:debug, :info, :warn, :error]
5359
quote
5460
old_logger = global_logger()
5561
io = IOContext(Core.stderr, :color=>STDERR_HAS_COLOR[])
56-
min_level = Logging.min_enabled_level(old_logger)
62+
min_level = _invoked_min_enabled_level(old_logger)
5763
global_logger(Logging.ConsoleLogger(io, min_level))
5864
ret = $(esc(macrocall))
5965
global_logger(old_logger)

0 commit comments

Comments
 (0)