couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [4/4] couch-log commit: updated refs/heads/master to fd40b31
Date Fri, 18 Sep 2015 13:43:48 GMT
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 <rnewson@apache.org>
Authored: Fri Sep 18 10:41:13 2015 +0100
Committer: Eric Avdey <eiri@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).
 


Mime
View raw message