Segfault trying to call Logger.global_logger

bug

#1

I’m trying to define a custom logging format to print timestamps and I’m running into a segfault. Probably part of it is just using some anti-pattern that I should avoid using but the segfault probably also shouldn’t happen. M(non)WE:

main.jl:

push!(LOAD_PATH, ".")

using mylogging
mylogging.setlogger()

function main()
	println("hello")
	@info "hello"
end

main()

mylogging.jl:

module mylogging

import Logging
import Logging:default_logcolor

function custom_metafmt(level, _module, group, id, file, line)
    color = default_logcolor(level)
    prefix = "custom prefix :"
    suffix = ": custom suffix"
    return color, prefix, suffix
end

const TESTLOGR = Logging.ConsoleLogger(meta_formatter = custom_metafmt)

function setlogger()
	Logging.global_logger(TESTLOGR)
end

end

Segfault:

 $ julia main.jl 
hello

signal (11): Segmentation fault: 11
in expression starting at /Users/pat/tmp/main.jl:11
uv___stream_fd at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-ed3700c849289ed01fe04273a7bf865340b2bd7e/src/unix/stream.c:1644
uv_tty_get_winsize at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-ed3700c849289ed01fe04273a7bf865340b2bd7e/src/unix/tty.c:243
displaysize at ./stream.jl:403
jfptr_displaysize_13121.clone_1 at /Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
#handle_message#2 at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Logging/src/ConsoleLogger.jl:109
unknown function (ip: 0x1271c5ae3)
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1831
handle_message at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Logging/src/ConsoleLogger.jl:100 [inlined]
macro expansion at ./logging.jl:322 [inlined]
main at /Users/pat/tmp/main.jl:8
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1831
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:324
eval_stmt_value at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:363 [inlined]
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x117385b3f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:813
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx64/build/src/ast.c:838
jl_load at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:847 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:854
include at ./boot.jl:317 [inlined]
include_relative at ./loading.jl:1041
include at ./sysimg.jl:29
exec_options at ./client.jl:229
_start at ./client.jl:421
true_main at /Users/pat/bin/julia (unknown line)
main at /Users/pat/bin/julia (unknown line)
Allocations: 739401 (Pool: 739219; Big: 182); GC: 0
Segmentation fault: 11

If I just import the module instead, it works as expected:

julia> include("mylogging.jl")
Main.mylogging

julia> @info "before"
[ Info: before

julia> mylogging.setlogger()
Logging.ConsoleLogger(Base.TTY(RawFD(0x00000011) open, 0 bytes waiting), Info, Logging.default_metafmt, true, 0, Dict{Any,Int64}())

julia> @info "after"
┌ custom prefix : after
└ : custom suffix

julia> 

Julia 1.0.1