From 72cf45ff3f4712c089cd29ab32dfcdfe326124e4 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Wed, 30 Nov 2011 14:44:39 -0500 Subject: [PATCH] Use lager for all log messages --- .gitignore | 1 + Makefile | 11 +++++++++-- ebin/bdberl.app | 2 +- rebar.config | 8 +++++++- src/bdberl.app.src | 5 +++-- src/bdberl.erl | 10 +++++----- src/bdberl_logger.erl | 12 ++++++------ 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 17a89cb..03cf53f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.so *.beam *.orig +deps logs doc include/BDBERL-MIB.hrl diff --git a/Makefile b/Makefile index 7c77fff..733d6c1 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,19 @@ CT_RUN ?=ct_run ERL_FLAGS ?=+A10 REBAR_FLAGS := -all: $(BDB_LOCAL_LIB) +all: deps compile + +deps: + $(REBAR) get-deps + +compile: $(BDB_LOCAL_LIB) ERL_FLAGS=$(ERL_FLAGS) $(REBAR) $(REBAR_FLAGS) compile test: tests tests: - @ $(REBAR) $(REBAR_FLAGS) eunit ct + @ $(REBAR) $(REBAR_FLAGS) eunit app=bdberl + @ $(REBAR) $(REBAR_FLAGS) ct app=bdberl thrash-test: @ $(CT_RUN) -pa test/ -suite thrash_SUITE @@ -20,6 +26,7 @@ clean: -rm test/*.beam distclean: clean + $(REBAR) delete-deps -make -C c_src clean -rm -rf c_src/sources -rm -rf priv diff --git a/ebin/bdberl.app b/ebin/bdberl.app index 848d866..e9d59e3 100644 --- a/ebin/bdberl.app +++ b/ebin/bdberl.app @@ -2,6 +2,6 @@ [{description,"This is an Erlang port driver that allows Erlang programs to store data in BerkleyDB."}, {vsn,"5.2.28"}, {registered,[]}, - {applications,[kernel,stdlib]}, + {applications,[kernel,stdlib,lager]}, {env,[]}, {modules,[bdberl,bdberl_logger]}]}. diff --git a/rebar.config b/rebar.config index 579ae9d..fc72691 100644 --- a/rebar.config +++ b/rebar.config @@ -4,8 +4,14 @@ %% ex: ft=erlang ts=4 sw=4 et %% +{require_otp_vsn, "R13B04|R14"}. {cover_enabled, true}. -{erl_opts, [warnings_as_errors]}. + +{deps, [ + {lager, ".*", {git, "git://github.com/basho/lager", {branch, "master"}}} + ]}. + +{erl_opts, [warnings_as_errors, {parse_transform, lager_transform}]}. {port_envs, [ {"DRV_CFLAGS", "$DRV_CFLAGS -Werror -I c_src/system/include"}, diff --git a/src/bdberl.app.src b/src/bdberl.app.src index d22496b..f05e18e 100644 --- a/src/bdberl.app.src +++ b/src/bdberl.app.src @@ -5,7 +5,8 @@ {registered, []}, {applications, [ kernel, - stdlib + stdlib, + lager ]}, {env, []} - ]}. \ No newline at end of file + ]}. diff --git a/src/bdberl.erl b/src/bdberl.erl index 55dc076..606fa20 100644 --- a/src/bdberl.erl +++ b/src/bdberl.erl @@ -571,7 +571,7 @@ transaction(Fun, Retries, TimeLeft, Opts) -> ok -> try Fun() of abort -> - error_logger:info_msg("function requested abort"), + lager:info("function requested abort"), ok = txn_abort(), {error, transaction_aborted}; @@ -595,7 +595,7 @@ transaction(Fun, Retries, TimeLeft, Opts) -> transaction(Fun, R, T, Opts); _ : Reason -> - error_logger:info_msg("function threw non-lock error - ~p", [Reason]), + lager:info("function threw non-lock error - ~p", [Reason]), ok = txn_abort(), {error, {transaction_failed, Reason}} end; @@ -900,7 +900,7 @@ get(Db, Key, Opts) -> Crc -> {ok, binary_to_term(Payload)}; CrcOther -> - error_logger:warning_msg("Invalid CRC: ~p ~p\n", [Crc, CrcOther]), + lager:warning("Invalid CRC: ~p ~p\n", [Crc, CrcOther]), {error, invalid_crc} end; not_found -> not_found; @@ -1386,7 +1386,7 @@ cursor_get(Key, Opts) -> Crc -> {ok, binary_to_term(Payload)}; CrcOther -> - error_logger:warning_msg("Invalid CRC: ~p ~p\n", [Crc, CrcOther]), + lager:warning("Invalid CRC: ~p ~p\n", [Crc, CrcOther]), {error, invalid_crc} end; not_found -> not_found; @@ -2439,7 +2439,7 @@ do_cursor_move(Direction) -> Crc -> {ok, binary_to_term(KeyBin), binary_to_term(Payload)}; CrcOther -> - error_logger:warning_msg("Invalid CRC on cursor: ~p ~p\n", [Crc, CrcOther]), + lager:warning("Invalid CRC on cursor: ~p ~p\n", [Crc, CrcOther]), {error, invalid_crc} end; not_found -> diff --git a/src/bdberl_logger.erl b/src/bdberl_logger.erl index 8f68063..fffd32d 100644 --- a/src/bdberl_logger.erl +++ b/src/bdberl_logger.erl @@ -67,9 +67,9 @@ init([]) -> true -> load_mibs(['BDBERL-MIB']); false -> - error_logger:warning_msg("SNMP is not running; bdberl stats will not be published.\n") + lager:warning("SNMP is not running; bdberl stats will not be published.\n") end, - + {ok, #state{}}. handle_call(_Request, _From, State) -> @@ -79,11 +79,11 @@ handle_cast(_Msg, State) -> {stop, unsupportedOperation, State}. handle_info({bdb_error_log, Msg}, State) -> - error_logger:error_msg("BDB Error: ~s\n", [Msg]), + lager:error("BDB Error: ~s\n", [Msg]), {noreply, State}; handle_info({bdb_info_log, Msg}, State) -> - error_logger:info_msg("BDB Info: ~s\n", [Msg]), + lager:info("BDB Info: ~s\n", [Msg]), {noreply, State}; handle_info({bdb_checkpoint_stats, CheckpointSecs, ArchiveSecs, 0, 0}, State) -> @@ -98,7 +98,7 @@ handle_info({bdb_checkpoint_stats, CheckpointSecs, ArchiveSecs, 0, 0}, State) -> {noreply, State}; handle_info({bdb_checkpoint_stats, _CheckpointSecs, _ArchiveSecs, CheckpointRc, ArchiveRc}, State) -> - error_logger:error_msg("BDB Checkpoint error: ~w ~w\n", [CheckpointRc, ArchiveRc]), + lager:error("BDB Checkpoint error: ~w ~w\n", [CheckpointRc, ArchiveRc]), {noreply, State}; handle_info({bdb_trickle_stats, ElapsedSecs, Pages, 0}, State) -> @@ -112,7 +112,7 @@ handle_info({bdb_trickle_stats, ElapsedSecs, Pages, 0}, State) -> end, {noreply, State}; handle_info({bdb_trickle_stats, _ElapsedSecs, _Pages, Rc}, State) -> - error_logger:error_msg("BDB Trickle Write error: ~w\n", [Rc]), + lager:error("BDB Trickle Write error: ~w\n", [Rc]), {noreply, State}; handle_info(Msg, State) ->