couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [3/3] couchdb-couch-log-lager git commit: Add tests and specs
Date Fri, 18 Sep 2015 13:48:21 GMT
Add tests and specs


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log-lager/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log-lager/commit/64cd100c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log-lager/tree/64cd100c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log-lager/diff/64cd100c

Branch: refs/heads/master
Commit: 64cd100cb566ce93af9ef168fa86f9f70424b77b
Parents: 50dc85f
Author: Eric Avdey <eiri@eiri.ca>
Authored: Thu Sep 17 18:57:59 2015 -0300
Committer: Robert Newson <rnewson@apache.org>
Committed: Fri Sep 18 14:47:48 2015 +0100

----------------------------------------------------------------------
 src/couch_log_lager.erl | 51 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-log-lager/blob/64cd100c/src/couch_log_lager.erl
----------------------------------------------------------------------
diff --git a/src/couch_log_lager.erl b/src/couch_log_lager.erl
index 1938365..b9364ea 100644
--- a/src/couch_log_lager.erl
+++ b/src/couch_log_lager.erl
@@ -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.


Mime
View raw message