Skip to content

Commit

Permalink
Merge pull request #12 from tanmaykm/tan/misc
Browse files Browse the repository at this point in the history
fix exception stack traces
  • Loading branch information
tanmaykm authored Oct 20, 2020
2 parents 4027ed1 + 06fa81a commit e7e053f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "c41e01d8-14e5-11ea-185b-e7eabed7be4b"
keywords = ["log", "rotate", "roller", "logrotate"]
license = "MIT"
authors = ["Tanmay Mohapatra <[email protected]>"]
version = "0.4.1"
version = "0.4.2"

[compat]
julia = "1.2,1.3,1.4,1.5"
Expand Down
4 changes: 3 additions & 1 deletion src/LogRoller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ function handle_message(logger::RollingLogger, level, message, _module, group, i
end
for (key, val) in kwargs
kwarg_timestamp && (key === logger.timestamp_identifier) && continue
println(iob, "", key, " = ", val)
print(iob, "", key, " = ")
Logging.showvalue(iob, val)
println(iob)
end
println(iob, "└ @ ", something(_module, "nothing"), " ", something(filepath, "nothing"), ":", something(line, "nothing"))
catch ex
Expand Down
41 changes: 40 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function test_json_format()

entry = JSON.parse(readio)
@test entry["metadata"]["level"] == "Info"
@test endswith(entry["message"], "Array{Bool,1}") # either "Array{Bool,1}" or "Vector{Bool} = Array{Bool,1}"
@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...)"

entry = JSON.parse(readio)
@test entry["metadata"]["level"] == "Error"
Expand Down Expand Up @@ -435,6 +435,43 @@ function test_size_limits()
end
end

function test_exception_printing()
mktempdir() do logdir
filename = "test.log"
filepath = joinpath(logdir, filename)

logger = RollingLogger(filepath, 2000, 3; format=:json)
with_logger(logger) do
try
error("test exception")
catch ex
@error("caught exception", exception=(ex,catch_backtrace()))
end
end
close(logger)
open(filepath) do readio
entry = JSON.parse(readio)
lines = readlines(IOBuffer(entry["keywords"]["exception"]))
@test length(lines) > 10
end
end
mktempdir() do logdir
filename = "test.log"
filepath = joinpath(logdir, filename)

logger = RollingLogger(filepath, 2000, 3; format=:console)
with_logger(logger) do
try
error("test exception")
catch ex
@error("caught exception", exception=(ex,catch_backtrace()))
end
end
close(logger)
@test length(readlines(filepath)) > 10
end
end

@testset "file writer" begin
test_filewriter()
end
Expand All @@ -450,4 +487,6 @@ end
test_postrotate()
test_json_format()
test_size_limits()
test_exception_printing()
end

2 comments on commit e7e053f

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/23299

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" e7e053f886accdd442f35cdb6a5e017a540b4074
git push origin v0.4.2

Please sign in to comment.