Github user rnewson commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-log/pull/4#discussion_r39838440
--- Diff: src/couch_log.erl ---
@@ -12,41 +12,115 @@
-module(couch_log).
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+-endif.
+
-export([debug/2, info/2, notice/2, warning/2, error/2, critical/2,
alert/2, emergency/2]).
-export([set_level/1]).
+-export([behaviour_info/1]).
+
+behaviour_info(callbacks) ->
+ [{debug, 2}, {info, 2}, {notice, 2}, {warning, 2},
+ {error, 2}, {critical, 2}, {alert, 2}, {set_level, 1}];
+behaviour_info(_) ->
+ undefined.
+
+-spec debug(string(), list()) -> ok.
debug(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, debug]),
- lager:debug(Fmt, Args).
+ Backend:debug(Fmt, Args).
+-spec info(string(), list()) -> ok.
info(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, info]),
- lager:info(Fmt, Args).
+ Backend:info(Fmt, Args).
+-spec notice(string(), list()) -> ok.
notice(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, notice]),
- lager:notice(Fmt, Args).
+ Backend:notice(Fmt, Args).
+-spec warning(string(), list()) -> ok.
warning(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, warning]),
- lager:warning(Fmt, Args).
+ Backend:warning(Fmt, Args).
+-spec error(string(), list()) -> ok.
error(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, 'error']),
- lager:error(Fmt, Args).
+ Backend:error(Fmt, Args).
+-spec critical(string(), list()) -> ok.
critical(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, critical]),
- lager:critical(Fmt, Args).
+ Backend:critical(Fmt, Args).
+-spec alert(string(), list()) -> ok.
alert(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, alert]),
- lager:alert(Fmt, Args).
+ Backend:alert(Fmt, Args).
+-spec emergency(string(), list()) -> ok.
emergency(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, emergency]),
- lager:emergency(Fmt, Args).
+ Backend: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].
+ {ok, Backend} = application:get_env(?MODULE, backend),
--- End diff --
should call get_backend()
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---