lager_common_test_backend #224

Merged
merged 4 commits into from Jul 22, 2014

3 participants

@joedevivo

Before every test, just lager_common_test_backend:bounce(Level) with the log level of your choice. Every message will be passed along to ct:pal/1 for your viewing pleasure in the common_test reports.

Also, you can call lager_common_test_backend:get_logs/0 to get a list of all log messages this backend has received during your test. You can then search that list for expected log messages.

attn: @vagabond and friends

@Vagabond

Don't bother with lager 1.2 compat, use lager_msg module correctly (don't destructure the record, it is opaque. use the getter/setters).

@Vagabond

The rest looks OK.

@joedevivo

Ha, I've written this handler in one form or another three times now, the 1.2 stuff is left over from the first one. Will remove.

@Vagabond Vagabond and 1 other commented on an outdated diff Jul 22, 2014
src/lager_common_test_backend.erl
+%% lager_common_test_backend:get_logs/0 to get a list of all log
+%% messages this backend has received during your test. You can then
+%% search that list for expected log messages.
+
+
+-spec get_logs() -> [iolist()] | {error, term()}.
+get_logs() ->
+ gen_event:call(lager_event, ?MODULE, get_logs, infinity).
+
+bounce() ->
+ bounce(error).
+
+bounce(Level) ->
+ application:stop(lager),
+ lager:start(),
+ gen_event:add_handler(lager_event, lager_common_test_backend, [error, false]),
@Vagabond
Vagabond added a line comment Jul 22, 2014

Why not instanciate with the right log level and avoid the set_loglevel on the next line?

@joedevivo
joedevivo added a line comment Jul 22, 2014

I don't remember. This was the way we did it in riak_test_lager_backend, and I believe there was some edge case that made this necessary. If the common_test version works without it, I'll fix it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Vagabond

+1 to merge.

@jaredmorrow jaredmorrow merged commit dd26760 into basho:master Jul 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment