You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/09/18 15:43:45 UTC
[1/4] couch-log commit: updated refs/heads/master to fd40b31
Repository: couchdb-couch-log
Updated Branches:
refs/heads/master ccbb81c3d -> fd40b3112
Convert couch_log into behaviour
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/6bb35011
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/6bb35011
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/6bb35011
Branch: refs/heads/master
Commit: 6bb35011c2f4a319e00ed33b06d710f22e651313
Parents: ccbb81c
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Sep 17 18:00:22 2015 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Thu Sep 17 18:00:22 2015 -0300
----------------------------------------------------------------------
src/couch_log.erl | 45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/6bb35011/src/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couch_log.erl b/src/couch_log.erl
index 8f85077..3b5e4f9 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -15,38 +15,63 @@
-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.
+
debug(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, debug]),
- lager:debug(Fmt, Args).
+ Backend:debug(Fmt, Args).
info(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, info]),
- lager:info(Fmt, Args).
+ Backend:info(Fmt, Args).
notice(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, notice]),
- lager:notice(Fmt, Args).
+ Backend:notice(Fmt, Args).
warning(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, warning]),
- lager:warning(Fmt, Args).
+ Backend:warning(Fmt, Args).
error(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, 'error']),
- lager:error(Fmt, Args).
+ Backend:error(Fmt, Args).
critical(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, critical]),
- lager:critical(Fmt, Args).
+ Backend:critical(Fmt, Args).
alert(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, alert]),
- lager:alert(Fmt, Args).
+ Backend:alert(Fmt, Args).
emergency(Fmt, Args) ->
+ {ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, emergency]),
- lager:emergency(Fmt, Args).
+ Backend:emergency(Fmt, Args).
set_level(Level) ->
- {ok, Handlers} = application:get_env(lager, handlers),
- [lager:set_loglevel(Handler, Level) || {Handler, _} <- Handlers].
+ {ok, Backend} = application:get_env(?MODULE, backend),
+ Backend:set_level(Level).
+
+get_backend() ->
+ case application:get_env(?MODULE, backend) of
+ undefined ->
+ ok = application:load(?MODULE),
+ get_backend();
+ {ok, Backend} ->
+ {ok, Backend}
+ end.
[2/4] couch-log commit: updated refs/heads/master to fd40b31
Posted by rn...@apache.org.
Add stderr logger implementation. Make it to fail-safe.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/49741262
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/49741262
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/49741262
Branch: refs/heads/master
Commit: 49741262fc0402a0fe4b62893410ce19eb045f81
Parents: 6bb3501
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Sep 17 18:03:02 2015 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Thu Sep 17 19:05:20 2015 -0300
----------------------------------------------------------------------
rebar.config | 7 ------
src/couch_log.app.src | 3 ++-
src/couch_log_stderr.erl | 57 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/49741262/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index dee56d4..e69de29 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,7 +0,0 @@
-{deps, [
- {lager, ".*", {git, "https://git-wip-us.apache.org/repos/asf/couchdb-lager.git", {branch, "master"}}}
-]}.
-
-{erl_opts, [debug_info, {parse_transform, lager_transform}]}.
-
-
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/49741262/src/couch_log.app.src
----------------------------------------------------------------------
diff --git a/src/couch_log.app.src b/src/couch_log.app.src
index f8372ca..b59b1e9 100644
--- a/src/couch_log.app.src
+++ b/src/couch_log.app.src
@@ -15,5 +15,6 @@
{vsn, git},
{modules, [couch_log]},
{registered, []},
- {applications, [kernel, stdlib, lager]}
+ {applications, [kernel, stdlib]},
+ {env, [{backend, couch_log_stderr}]}
]}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/49741262/src/couch_log_stderr.erl
----------------------------------------------------------------------
diff --git a/src/couch_log_stderr.erl b/src/couch_log_stderr.erl
new file mode 100644
index 0000000..6bf95b9
--- /dev/null
+++ b/src/couch_log_stderr.erl
@@ -0,0 +1,57 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_log_stderr).
+
+-behaviour(couch_log).
+
+-export([
+ debug/2,
+ info/2,
+ notice/2,
+ warning/2,
+ error/2,
+ critical/2,
+ alert/2,
+ emergency/2,
+ set_level/1
+]).
+
+debug(Fmt, Args) ->
+ write_log("[debug] " ++ Fmt, Args).
+
+info(Fmt, Args) ->
+ write_log("[info] " ++ Fmt, Args).
+
+notice(Fmt, Args) ->
+ write_log("[notice] " ++ Fmt, Args).
+
+warning(Fmt, Args) ->
+ write_log("[warning] " ++ Fmt, Args).
+
+error(Fmt, Args) ->
+ write_log("[error] " ++ Fmt, Args).
+
+critical(Fmt, Args) ->
+ write_log("[critical] " ++ Fmt, Args).
+
+alert(Fmt, Args) ->
+ write_log("[alert] " ++ Fmt, Args).
+
+emergency(Fmt, Args) ->
+ write_log("[emergency] " ++ Fmt, Args).
+
+write_log(Fmt, Args) ->
+ io:format(standard_error, Fmt ++ "~n", Args).
+
+set_level(_) ->
+ ok.
[4/4] couch-log commit: updated refs/heads/master to fd40b31
Posted by rn...@apache.org.
Choose backend at build time
This allows us to set the backend as a dependency of the front end,
ensuring it is started first. This also means we don't need to call
application:load/1.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/fd40b311
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/fd40b311
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/fd40b311
Branch: refs/heads/master
Commit: fd40b31125f806f9a5faab413de84698c08d59de
Parents: f3b894e
Author: Robert Newson <rn...@apache.org>
Authored: Fri Sep 18 10:41:13 2015 +0100
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Fri Sep 18 10:36:15 2015 -0300
----------------------------------------------------------------------
src/couch_log.app.src | 20 -------------------
src/couch_log.app.src.script | 42 +++++++++++++++++++++++++++++++++++++++
src/couch_log.erl | 11 ++--------
3 files changed, 44 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/fd40b311/src/couch_log.app.src
----------------------------------------------------------------------
diff --git a/src/couch_log.app.src b/src/couch_log.app.src
deleted file mode 100644
index b59b1e9..0000000
--- a/src/couch_log.app.src
+++ /dev/null
@@ -1,20 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-{application, couch_log, [
- {description, "CouchDB Log API"},
- {vsn, git},
- {modules, [couch_log]},
- {registered, []},
- {applications, [kernel, stdlib]},
- {env, [{backend, couch_log_stderr}]}
-]}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/fd40b311/src/couch_log.app.src.script
----------------------------------------------------------------------
diff --git a/src/couch_log.app.src.script b/src/couch_log.app.src.script
new file mode 100644
index 0000000..8fd7b02
--- /dev/null
+++ b/src/couch_log.app.src.script
@@ -0,0 +1,42 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
+ true ->
+ {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")),
+ Result;
+ false ->
+ []
+end.
+
+Backend = case lists:keyfind(couch_log_backend, 1, CouchConfig) of
+ {couch_log_backend, Backend0} ->
+ Backend0;
+ false ->
+ couch_log_stderr
+end.
+
+BackendApps = case lists:keyfind(couch_log_backend_apps, 1, CouchConfig) of
+ {couch_log_backend_apps, Apps} ->
+ Apps;
+ false ->
+ []
+end.
+
+{application, couch_log, [
+ {description, "CouchDB Log API"},
+ {vsn, git},
+ {modules, [couch_log]},
+ {registered, []},
+ {applications, [kernel, stdlib] ++ BackendApps},
+ {env, [{backend, Backend}]}
+]}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/fd40b311/src/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couch_log.erl b/src/couch_log.erl
index 0c10230..e80685a 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -77,19 +77,12 @@ emergency(Fmt, Args) ->
-spec set_level(atom()) -> ok.
set_level(Level) ->
- {ok, Backend} = application:get_env(?MODULE, backend),
+ {ok, Backend} = get_backend(),
Backend:set_level(Level).
-spec get_backend() -> {ok, atom()}.
get_backend() ->
- case application:get_env(?MODULE, backend) of
- undefined ->
- ok = application:load(?MODULE),
- get_backend();
- {ok, Backend} ->
- {ok, Backend}
- end.
-
+ application:get_env(?MODULE, backend).
-ifdef(TEST).
[3/4] couch-log commit: updated refs/heads/master to fd40b31
Posted by rn...@apache.org.
Add tests and specs
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/f3b894e6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/f3b894e6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/f3b894e6
Branch: refs/heads/master
Commit: f3b894e6f660243fc292256ae32a0f6925005fae
Parents: 4974126
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Sep 17 18:07:44 2015 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Fri Sep 18 10:36:00 2015 -0300
----------------------------------------------------------------------
.gitignore | 2 ++
rebar.config | 15 +++++++++++++++
src/couch_log.erl | 45 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 3b66f4e..e24db8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
/ebin
+.eunit
+.rebar
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index e69de29..7104d3b 100644
--- a/rebar.config
+++ b/rebar.config
@@ -0,0 +1,15 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{deps, [
+ {meck, ".*", {git, "https://git-wip-us.apache.org/repos/asf/couchdb-meck.git", {tag, "0.8.2"}}}
+]}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/src/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couch_log.erl b/src/couch_log.erl
index 3b5e4f9..0c10230 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -12,6 +12,10 @@
-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]).
@@ -23,50 +27,60 @@ behaviour_info(callbacks) ->
behaviour_info(_) ->
undefined.
+-spec debug(string(), list()) -> ok.
debug(Fmt, Args) ->
{ok, Backend} = get_backend(),
catch couch_stats:increment_counter([couch_log, level, debug]),
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]),
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]),
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]),
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']),
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]),
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]),
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]),
Backend:emergency(Fmt, Args).
+-spec set_level(atom()) -> ok.
set_level(Level) ->
{ok, Backend} = application:get_env(?MODULE, backend),
Backend:set_level(Level).
+-spec get_backend() -> {ok, atom()}.
get_backend() ->
case application:get_env(?MODULE, backend) of
undefined ->
@@ -75,3 +89,34 @@ get_backend() ->
{ok, Backend} ->
{ok, Backend}
end.
+
+
+-ifdef(TEST).
+
+callbacks_test_() ->
+ {setup,
+ fun setup/0,
+ fun cleanup/1,
+ [
+ ?_assertEqual({ok, couch_log_stderr}, get_backend()),
+ ?_assertEqual(ok, couch_log:debug("message", [])),
+ ?_assertEqual(ok, couch_log:info("message", [])),
+ ?_assertEqual(ok, couch_log:notice("message", [])),
+ ?_assertEqual(ok, couch_log:warning("message", [])),
+ ?_assertEqual(ok, couch_log:error("message", [])),
+ ?_assertEqual(ok, couch_log:critical("message", [])),
+ ?_assertEqual(ok, couch_log:alert("message", [])),
+ ?_assertEqual(ok, couch_log:emergency("message", [])),
+ ?_assertEqual(ok, couch_log:set_level(info))
+ ]
+ }.
+
+setup() ->
+ meck:new([couch_stats]),
+ meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
+ application:load(?MODULE).
+
+cleanup(_) ->
+ meck:unload([couch_stats]).
+
+-endif.