Skip to content

Commit

Permalink
logging: string->String (#44567)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Mar 17, 2022
1 parent 1c1d99c commit e191c6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit e191c6e

Please sign in to comment.