summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Leeds <randall@apache.org>2013-01-26 09:59:03 -0800
committerRandall Leeds <randall@apache.org>2013-01-26 09:59:03 -0800
commita1461a2b92f8cbd89f0aebe7339e754836d14202 (patch)
tree1c3cde38e334ed8e974925745b48e0bf080f8a20
parent93f58e8adcb04555df7da400ed21800cb97ba19c (diff)
downloadcouchdb-a1461a2b92f8cbd89f0aebe7339e754836d14202.tar.gz
add a ?LOG_WARN and warning level for couch_log
-rw-r--r--src/couchdb/couch_db.hrl7
-rw-r--r--src/couchdb/couch_log.erl18
2 files changed, 24 insertions, 1 deletions
diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl
index 325fb98ce..eb34ed562 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
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index 906a8beba..7faa68d69 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};