Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module,
end
iob = IOContext(buf, stream)
levelstr = level == Warn ? "Warning" : string(level)
msglines = eachsplit(chomp(string(message)::String), '\n')
msglines = eachsplit(chomp(convert(String, string(message))::String), '\n')
msg1, rest = Iterators.peel(msglines)
println(iob, "┌ ", levelstr, ": ", msg1)
for msg in rest
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Logging/src/ConsoleLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module

# Generate a text representation of the message and all key value pairs,
# split into lines.
msglines = [(indent=0, msg=l) for l in split(chomp(string(message)::String), '\n')]
msglines = [(indent=0, msg=l) for l in split(chomp(convert(String, string(message))::String), '\n')]
stream = logger.stream
if !isopen(stream)
stream = stderr
Expand Down
15 changes: 15 additions & 0 deletions test/corelogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ end
@test_throws MethodError @macrocall(@error)
end

@testset "Any type" begin
@test_logs (:info, sum) @info sum
# TODO: make this work (here we want `@test_logs` to fail)
# @test_fails @test_logs (:info, "sum") @info sum # `sum` works, `"sum"` does not

# check that the message delivered to the user works
mktempdir() do dir
path_stdout = joinpath(dir, "stdout.txt")
path_stderr = joinpath(dir, "stderr.txt")
redirect_stdio(stdout=path_stdout, stderr=path_stderr) do
@info sum
end
@test occursin("Info: sum", read(path_stderr, String))
end
end

#-------------------------------------------------------------------------------
# Early log level filtering
Expand Down