Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Add tests and specs
  • Loading branch information
eiri authored and rnewson committed Sep 18, 2015
1 parent 50dc85f commit 64cd100cb566ce93af9ef168fa86f9f70424b77b
Showing 1 changed file with 50 additions and 1 deletion.
@@ -14,6 +14,10 @@

-behaviour(couch_log).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

-export([
debug/2,
info/2,
@@ -26,30 +30,75 @@
set_level/1
]).

-spec debug(string(), list()) -> ok.
debug(Fmt, Args) ->
lager:debug(Fmt, Args).

-spec info(string(), list()) -> ok.
info(Fmt, Args) ->
lager:info(Fmt, Args).

-spec notice(string(), list()) -> ok.
notice(Fmt, Args) ->
lager:notice(Fmt, Args).

-spec warning(string(), list()) -> ok.
warning(Fmt, Args) ->
lager:warning(Fmt, Args).

-spec error(string(), list()) -> ok.
error(Fmt, Args) ->
lager:error(Fmt, Args).

-spec critical(string(), list()) -> ok.
critical(Fmt, Args) ->
lager:critical(Fmt, Args).

-spec alert(string(), list()) -> ok.
alert(Fmt, Args) ->
lager:alert(Fmt, Args).

-spec emergency(string(), list()) -> ok.
emergency(Fmt, Args) ->
lager:emergency(Fmt, Args).

-spec set_level(atom()) -> ok.
set_level(Level) ->
{ok, Handlers} = application:get_env(lager, handlers),
[lager:set_loglevel(Handler, Level) || {Handler, _} <- Handlers].
lists:foreach(fun({Handler, _}) ->
lager:set_loglevel(Handler, Level)
end, Handlers).


-ifdef(TEST).

callbacks_test_() ->
{setup,
fun setup/0,
fun cleanup/1,
[
?_assertEqual(info, lager:get_loglevel(lager_console_backend)),
?_assertEqual(ok, set_level(debug)),
?_assertEqual(debug, lager:get_loglevel(lager_console_backend)),
?_assertEqual(ok, set_level(alert)),
?_assertEqual(alert, lager:get_loglevel(lager_console_backend))
]
}.

setup() ->
setup_lager().

setup_lager() ->
error_logger:tty(false),
application:load(lager),
application:set_env(lager, handlers, [{lager_console_backend, info}]),
application:set_env(lager, error_logger_redirect, false),
application:set_env(lager, async_threshold, undefined),
lager:start().

cleanup(_) ->
application:stop(lager),
application:stop(goldrush),
error_logger:tty(true).

-endif.

0 comments on commit 64cd100

Please sign in to comment.