couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rand...@apache.org
Subject [1/2] git commit: add a ?LOG_WARN and warning level for couch_log
Date Sat, 26 Jan 2013 18:14:09 GMT
add a ?LOG_WARN and warning level for couch_log


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/a1461a2b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a1461a2b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a1461a2b

Branch: refs/heads/1569-feature-low-disk-space-warn
Commit: a1461a2b92f8cbd89f0aebe7339e754836d14202
Parents: 93f58e8
Author: Randall Leeds <randall@apache.org>
Authored: Sat Jan 26 09:59:03 2013 -0800
Committer: Randall Leeds <randall@apache.org>
Committed: Sat Jan 26 09:59:03 2013 -0800

----------------------------------------------------------------------
 src/couchdb/couch_db.hrl  |    7 +++++++
 src/couchdb/couch_log.erl |   18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a1461a2b/src/couchdb/couch_db.hrl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl
index 325fb98..eb34ed5 100644
--- a/src/couchdb/couch_db.hrl
+++ b/src/couchdb/couch_db.hrl
@@ -50,6 +50,13 @@
         false -> ok
     end).
 
+-define(LOG_WARN(Format, Args),
+    case couch_log:warn_on(?MODULE) of
+        true ->
+            couch_log:info(Format, Args);
+        false -> ok
+    end).
+
 -define(LOG_ERROR(Format, Args), couch_log:error(Format, Args)).
 
 % Tree::term() is really a tree(), but we don't want to require R13B04 yet

http://git-wip-us.apache.org/repos/asf/couchdb/blob/a1461a2b/src/couchdb/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index 906a8be..7faa68d 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -24,7 +24,8 @@
 -export([init/1, handle_event/2, terminate/2, code_change/3]).
 -export([handle_info/2, handle_call/2]).
 
--define(LEVEL_ERROR, 3).
+-define(LEVEL_ERROR, 4).
+-define(LEVEL_WARN, 3).
 -define(LEVEL_INFO, 2).
 -define(LEVEL_DEBUG, 1).
 
@@ -42,17 +43,23 @@ info(Format, Args) ->
     {ConsoleMsg, FileMsg} = get_log_messages(self(), info, Format, Args),
     gen_event:sync_notify(error_logger, {couch_info, ConsoleMsg, FileMsg}).
 
+warn(Format, Args) ->
+    {ConsoleMsg, FileMsg} = get_log_messages(self(), warn, Format, Args),
+    gen_event:sync_notify(error_logger, {couch_warn, ConsoleMsg, FileMsg}).
+
 error(Format, Args) ->
     {ConsoleMsg, FileMsg} = get_log_messages(self(), error, Format, Args),
     gen_event:sync_notify(error_logger, {couch_error, ConsoleMsg, FileMsg}).
 
 
 level_integer(error)    -> ?LEVEL_ERROR;
+level_integer(warn)     -> ?LEVEL_WARN;
 level_integer(info)     -> ?LEVEL_INFO;
 level_integer(debug)    -> ?LEVEL_DEBUG;
 level_integer(_Else)    -> ?LEVEL_ERROR. % anything else default to ERROR level
 
 level_atom(?LEVEL_ERROR) -> error;
+level_atom(?LEVEL_WARN) -> warn;
 level_atom(?LEVEL_INFO) -> info;
 level_atom(?LEVEL_DEBUG) -> debug.
 
@@ -110,12 +117,18 @@ debug_on() ->
 info_on() ->
     get_level_integer() =< ?LEVEL_INFO.
 
+warn_on() ->
+    get_level_integer() =< ?LEVEL_WARN.
+
 debug_on(Module) ->
     get_level_integer(Module) =< ?LEVEL_DEBUG.
 
 info_on(Module) ->
     get_level_integer(Module) =< ?LEVEL_INFO.
 
+warn_on(Module) ->
+    get_level_integer(Module) =< ?LEVEL_WARN.
+
 set_level(LevelAtom) ->
     set_level_integer(level_integer(LevelAtom)).
 
@@ -153,6 +166,9 @@ set_level_integer(Module, Int) ->
 handle_event({couch_error, ConMsg, FileMsg}, State) ->
     log(State, ConMsg, FileMsg),
     {ok, State};
+handle_event({couch_warn, ConMsg, FileMsg}, State) ->
+    log(State, ConMsg, FileMsg),
+    {ok, State};
 handle_event({couch_info, ConMsg, FileMsg}, State) ->
     log(State, ConMsg, FileMsg),
     {ok, State};


Mime
View raw message