diff options
author | Peng Hui Jiang <jiangph@cn.ibm.com> | 2017-12-15 10:28:19 +0800 |
---|---|---|
committer | Eric Avdey <eiri@eiri.ca> | 2017-12-14 22:28:19 -0400 |
commit | beb87817f7dfaeb9ce2763147ddde9d6d29ffc6e (patch) | |
tree | 10fd9b8f579697c8bf9942cc8179d0b7d592fd5a | |
parent | f8e56e91b2fe68c392858c2b8770d305c3d6b3b0 (diff) | |
download | couchdb-beb87817f7dfaeb9ce2763147ddde9d6d29ffc6e.tar.gz |
Add couch_stats tracking back to couch_log (#1064)
issue #832
-rw-r--r-- | src/couch_log/src/couch_log.erl | 32 | ||||
-rw-r--r-- | src/couch_log/test/couch_log_test_util.erl | 7 | ||||
-rw-r--r-- | src/couch_stats/src/couch_stats.app.src | 2 | ||||
-rw-r--r-- | src/couch_stats/src/couch_stats.erl | 2 | ||||
-rw-r--r-- | src/couch_stats/src/couch_stats_process_tracker.erl | 8 |
5 files changed, 35 insertions, 16 deletions
diff --git a/src/couch_log/src/couch_log.erl b/src/couch_log/src/couch_log.erl index 0ce4739a4..a80d4a477 100644 --- a/src/couch_log/src/couch_log.erl +++ b/src/couch_log/src/couch_log.erl @@ -28,35 +28,51 @@ -spec debug(string(), list()) -> ok. -debug(Fmt, Args) -> log(debug, Fmt, Args). +debug(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, debug]), + log(debug, Fmt, Args). -spec info(string(), list()) -> ok. -info(Fmt, Args) -> log(info, Fmt, Args). +info(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, info]), + log(info, Fmt, Args). -spec notice(string(), list()) -> ok. -notice(Fmt, Args) -> log(notice, Fmt, Args). +notice(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, notice]), + log(notice, Fmt, Args). -spec warning(string(), list()) -> ok. -warning(Fmt, Args) -> log(warning, Fmt, Args). +warning(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, warning]), + log(warning, Fmt, Args). -spec error(string(), list()) -> ok. -error(Fmt, Args) -> log(error, Fmt, Args). +error(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, error]), + log(error, Fmt, Args). -spec critical(string(), list()) -> ok. -critical(Fmt, Args) -> log(critical, Fmt, Args). +critical(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, critical]), + log(critical, Fmt, Args). -spec alert(string(), list()) -> ok. -alert(Fmt, Args) -> log(alert, Fmt, Args). +alert(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, alert]), + log(alert, Fmt, Args). -spec emergency(string(), list()) -> ok. -emergency(Fmt, Args) -> log(emergency, Fmt, Args). +emergency(Fmt, Args) -> + couch_stats:increment_counter([couch_log, level, emergency]), + log(emergency, Fmt, Args). -spec set_level(atom() | string() | integer()) -> true. diff --git a/src/couch_log/test/couch_log_test_util.erl b/src/couch_log/test/couch_log_test_util.erl index 250366982..05d64d8a9 100644 --- a/src/couch_log/test/couch_log_test_util.erl +++ b/src/couch_log/test/couch_log_test_util.erl @@ -22,12 +22,15 @@ start() -> application:set_env(config, ini_files, config_files()), application:start(config), ignore_common_loggers(), - application:start(couch_log). + application:start(couch_log), + meck:new(couch_stats), + ok = meck:expect(couch_stats, increment_counter, ['_'], ok). stop(_) -> application:stop(config), - application:stop(couch_log). + application:stop(couch_log), + meck:unload(couch_stats). with_level(Name, Fun) -> diff --git a/src/couch_stats/src/couch_stats.app.src b/src/couch_stats/src/couch_stats.app.src index 6339a0f1d..990f8de62 100644 --- a/src/couch_stats/src/couch_stats.app.src +++ b/src/couch_stats/src/couch_stats.app.src @@ -14,7 +14,7 @@ {description, "Simple statistics collection"}, {vsn, git}, {registered, [couch_stats_aggregator, couch_stats_process_tracker]}, - {applications, [kernel, stdlib, folsom, couch_log]}, + {applications, [kernel, stdlib, folsom]}, {mod, {couch_stats_app, []}}, {env, []} ]}. diff --git a/src/couch_stats/src/couch_stats.erl b/src/couch_stats/src/couch_stats.erl index 59175f7a8..4fde14acb 100644 --- a/src/couch_stats/src/couch_stats.erl +++ b/src/couch_stats/src/couch_stats.erl @@ -119,7 +119,7 @@ notify_existing_metric(Name, Op, Type) -> try ok = folsom_metrics:notify_existing_metric(Name, Op, Type) catch _:_ -> - couch_log:notice("unknown metric: ~p", [Name]), + error_logger:error_msg("unknown metric: ~p", [Name]), {error, unknown_metric} end. diff --git a/src/couch_stats/src/couch_stats_process_tracker.erl b/src/couch_stats/src/couch_stats_process_tracker.erl index 4765734e9..7d16deb8a 100644 --- a/src/couch_stats/src/couch_stats_process_tracker.erl +++ b/src/couch_stats/src/couch_stats_process_tracker.erl @@ -48,7 +48,7 @@ init([]) -> {ok, #st{}}. handle_call(Msg, _From, State) -> - couch_log:notice("~p received unknown call ~p", [?MODULE, Msg]), + error_logger:error_msg("~p received unknown call ~p", [?MODULE, Msg]), {noreply, State}. handle_cast({track, Pid, Name}, State) -> @@ -57,13 +57,13 @@ handle_cast({track, Pid, Name}, State) -> ets:insert(?MODULE, {Ref, Name}), {noreply, State}; handle_cast(Msg, State) -> - couch_log:notice("~p received unknown cast ~p", [?MODULE, Msg]), + error_logger:error_msg("~p received unknown cast ~p", [?MODULE, Msg]), {noreply, State}. handle_info({'DOWN', Ref, _, _, _}=Msg, State) -> case ets:lookup(?MODULE, Ref) of [] -> - couch_log:notice( + error_logger:error_msg( "~p received unknown exit; message was ~p", [?MODULE, Msg] ); [{Ref, Name}] -> @@ -72,7 +72,7 @@ handle_info({'DOWN', Ref, _, _, _}=Msg, State) -> end, {noreply, State}; handle_info(Msg, State) -> - couch_log:notice("~p received unknown message ~p", [?MODULE, Msg]), + error_logger:error_msg("~p received unknown message ~p", [?MODULE, Msg]), {noreply, State}. terminate(_Reason, _State) -> |