Skip to content

Commit e7e053f

Browse files
authored
Merge pull request #12 from tanmaykm/tan/misc
fix exception stack traces
2 parents 4027ed1 + 06fa81a commit e7e053f

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "c41e01d8-14e5-11ea-185b-e7eabed7be4b"
33
keywords = ["log", "rotate", "roller", "logrotate"]
44
license = "MIT"
55
authors = ["Tanmay Mohapatra <[email protected]>"]
6-
version = "0.4.1"
6+
version = "0.4.2"
77

88
[compat]
99
julia = "1.2,1.3,1.4,1.5"

src/LogRoller.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ function handle_message(logger::RollingLogger, level, message, _module, group, i
258258
end
259259
for (key, val) in kwargs
260260
kwarg_timestamp && (key === logger.timestamp_identifier) && continue
261-
println(iob, "", key, " = ", val)
261+
print(iob, "", key, " = ")
262+
Logging.showvalue(iob, val)
263+
println(iob)
262264
end
263265
println(iob, "└ @ ", something(_module, "nothing"), " ", something(filepath, "nothing"), ":", something(line, "nothing"))
264266
catch ex

test/runtests.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ function test_json_format()
361361

362362
entry = JSON.parse(readio)
363363
@test entry["metadata"]["level"] == "Info"
364-
@test endswith(entry["message"], "Array{Bool,1}") # either "Array{Bool,1}" or "Vector{Bool} = Array{Bool,1}"
364+
@test endswith(entry["message"], "Array{Bool,1}") || startswith(entry["message"], "Vector{Bool}") # either "Array{Bool,1}" or "Vector{Bool} = Array{Bool,1} or Vector{Bool} (alias for...)"
365365

366366
entry = JSON.parse(readio)
367367
@test entry["metadata"]["level"] == "Error"
@@ -435,6 +435,43 @@ function test_size_limits()
435435
end
436436
end
437437

438+
function test_exception_printing()
439+
mktempdir() do logdir
440+
filename = "test.log"
441+
filepath = joinpath(logdir, filename)
442+
443+
logger = RollingLogger(filepath, 2000, 3; format=:json)
444+
with_logger(logger) do
445+
try
446+
error("test exception")
447+
catch ex
448+
@error("caught exception", exception=(ex,catch_backtrace()))
449+
end
450+
end
451+
close(logger)
452+
open(filepath) do readio
453+
entry = JSON.parse(readio)
454+
lines = readlines(IOBuffer(entry["keywords"]["exception"]))
455+
@test length(lines) > 10
456+
end
457+
end
458+
mktempdir() do logdir
459+
filename = "test.log"
460+
filepath = joinpath(logdir, filename)
461+
462+
logger = RollingLogger(filepath, 2000, 3; format=:console)
463+
with_logger(logger) do
464+
try
465+
error("test exception")
466+
catch ex
467+
@error("caught exception", exception=(ex,catch_backtrace()))
468+
end
469+
end
470+
close(logger)
471+
@test length(readlines(filepath)) > 10
472+
end
473+
end
474+
438475
@testset "file writer" begin
439476
test_filewriter()
440477
end
@@ -450,4 +487,6 @@ end
450487
test_postrotate()
451488
test_json_format()
452489
test_size_limits()
490+
test_exception_printing()
453491
end
492+

0 commit comments

Comments
 (0)