@test_logs [log_patterns...] [keywords] expression
Collect a list of log records generated by expression using collect_test_logs, check that they match the sequence log_patterns, and return the value of expression. The keywords provide some simple filtering
of log records: the min_level keyword controls the minimum log level which will be collected for the test, the match_mode keyword defines how matching will be performed (the default :all checks that all logs
and patterns match pairwise; use :any to check that the pattern matches at least once somewhere in the sequence.)
The most useful log pattern is a simple tuple of the form (level,message). A different number of tuple elements may be used to match other log metadata, corresponding to the arguments to passed to
AbstractLogger via the handle_message function: (level,message,module,group,id,file,line). Elements which are present will be matched pairwise with the log record fields using == by default, with the special
cases that Symbols may be used for the standard log levels, and Regexs in the pattern will match string or Symbol fields using contains.
Consider a function which logs a warning, and several debug messages:
@info "Doing foo with n=$n"
@debug "Iteration $i"
We can test the info message using
@test_logs (:info,"Doing foo with n=2") foo(2)
If we also wanted to test the debug messages, these need to be enabled with the min_level keyword:
@test_logs (:info,"Doing foo with n=2") (:debug,"Iteration 1") (:debug,"Iteration 2") min_level=Debug foo(2)
The macro may be chained with @test to also test the returned value:
@test (@test_logs (:info,"Doing foo with n=2") foo(2)) == 42