Skip to content

Commit

Permalink
fix bug and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Adams authored and c42f committed Oct 31, 2018
1 parent 78a09c6 commit d3a7e83
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 20 additions & 0 deletions stdlib/Logging/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ import Logging: min_enabled_level, shouldlog, handle_message
handle_message(logger, Logging.Info, "msg", Base, :group, :asdf, "somefile", 1, maxlog=2)
@test shouldlog(logger, Logging.Info, Base, :group, :asdf) === false

# Check that maxlog works without an explicit ID
buf = IOBuffer()
io = IOContext(buf, :displaysize=>(30,80), :color=>false)
logger = ConsoleLogger(io)
with_logger(logger) do
for i in 1:2
@info "test" maxlog=1
end
end
@test String(take!(buf)) ==
"""
[ Info: test
"""
with_logger(logger) do
for i in 1:2
@info "test" maxlog=0
end
end
@test String(take!(buf)) == ""

@testset "Default metadata formatting" begin
@test Logging.default_metafmt(Logging.Debug, Base, :g, :i, expanduser("~/somefile.jl"), 42) ==
(:blue, "Debug:", "@ Base ~/somefile.jl:42")
Expand Down
19 changes: 18 additions & 1 deletion test/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ end
@test record.file == Base.source_path()
@test record.line == kwargs[:real_line]
@test record.id isa Symbol
@test occursin(r"^.*logging_[[:xdigit:]]{8}$", String(record.id))
@test occursin(r"^.*[[:xdigit:]]{8}$", String(record.id))

# User-defined metadata
@test kwargs[:bar_val] === bar_val
Expand Down Expand Up @@ -338,4 +338,21 @@ end
@test_logs (:warn, "a", Base) (@warn "a" _module=Base)
end

@testset "ID generation" begin
id1 = Base.CoreLogging.log_record_id(Main, "test.jl", 42, Info, ())
id2 = Base.CoreLogging.log_record_id(Main, "test.jl", 42, Info, ())
@test id1 == id2

logs,_ = collect_test_logs() do
for i in 1:2
@info "test"
@info "test"
end
end
@test length(logs) == 4
@test logs[1].id == logs[3].id
@test logs[2].id == logs[4].id
@test logs[1].id != logs[2].id
end

end

0 comments on commit d3a7e83

Please sign in to comment.