Permalink
Browse files

implemented new loggin framework, lager

  • Loading branch information...
Joachim
Joachim committed Mar 12, 2013
1 parent e7482d4 commit f48a329d58ba9848f8e92d4ab6525df7a804d2b5
View
@@ -6,4 +6,5 @@ ebin
deps
erl_crash.dump
logs/
+log/
*~
View
@@ -1,4 +1,4 @@
-{"src/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/elog/include"}]}.
-{"src/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/elog/include"}]}.
-{"test/*", [warn_unused_vars, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/elog/include"}]}.
-{"test/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/elog/include"}]}.
+{"src/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}.
+{"src/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}.
+{"test/*", [warn_unused_vars, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}.
+{"test/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}.
View
@@ -2,7 +2,7 @@
# Copyright (C) 2011 Electronic Inaka, LLC <contact at inakanetworks dot com>
# edis is licensed by Electronic Inaka, LLC under the Apache 2.0 license
-ERL := erl -pa deps/*/ebin -pa ebin -pa src -boot start_sasl +Bc +K true -smp enable -s crypto -s inets -s ssl -s elog ${ERL_ARGS}
+ERL := erl -pa deps/*/ebin -pa ebin -pa src -boot start_sasl +Bc +K true -smp enable -s crypto -s inets -s ssl -s lager ${ERL_ARGS}
PREFIX= /usr/local
INSTALL_BIN= $(PREFIX)/bin
INSTALL= cp -p
@@ -32,7 +32,7 @@ run: erl
${ERL} -s edis
test: erl
- ${ERL} -config test/test.config -noshell -sname edis_test_server -s edis -run elog debug &
+ ${ERL} -config test/test.config -noshell -sname edis_test_server -s edis &
mkdir -p ./test/ebin
erlc -o ./test/ebin +debug_info ./test/*_SUITE.erl
rebar skip_deps=true ct ; \
View
@@ -32,5 +32,4 @@ edis is licensed by Electronic Inaka, LLC under the Apache 2.0 license; see the
* Make use of the efficient range searchs with start/end for searching ranges
* Make use of time-based key expiry
* Finish the TODO items
-* Logging
- * Swap out elog for lager
+
View
@@ -2,6 +2,11 @@
{sync, {seconds, 10}},
{compress, none},
{block_size, 32768}] }}]},
- {elog, [{logger, {elogger_console, []}}]},
+ {lager, [
+ {handlers,
+ [
+ {lager_console_backend, [debug,true]}
+ ]}
+ ]},
{sasl, [{errlog_type, all},
{sasl_error_logger, {file, "logs/hanoidb.edis.sasl.log"}}]}].
View
@@ -1,4 +1,3 @@
--include("elog.hrl").
-define(POS_INFINITY,1.7976931348623157e308).
-define(NEG_INFINITY,-1.7976931348623157e308).
View
@@ -1,4 +1,9 @@
[{edis, [{listener_port_range, {6380, 6380}}, {dir, "db"}]},
- {elog, [{logger, {elogger_file, [{file, "logs/leveldb.edis.log"}, {size_limit, 2000}, {date_break, false}]}}]},
+ {lager, [
+ {handlers,
+ [
+ {lager_console_backend, [debug,true]}
+ ]}
+ ]},
{sasl, [{errlog_type, all},
{sasl_error_logger, {file, "logs/leveldb.edis.sasl.log"}}]}].
View
@@ -1,4 +1,9 @@
[{edis, [{listener_port_range, {6381, 6381}}, {backend, {edis_pd_backend, []}}]},
- {elog, [{logger, {elogger_console, []}}]},
+ {lager, [
+ {handlers,
+ [
+ {lager_console_backend, [debug,true]}
+ ]}
+ ]},
{sasl, [{errlog_type, all},
{sasl_error_logger, {file, "logs/pd.edis.sasl.log"}}]}].
View
@@ -23,11 +23,11 @@
{requirepass, undefined},
% edis_backend implementation to use as the backend for edis
{backend, {edis_eleveldb_backend, [{create_if_missing, true}]}}]},
- {elog, [{level, debug},
- {logger, {elogger_file, [{file, "/var/log/edis/edis.log"},
- {size_limit, 2000},
- {date_break, false}]}},
- {debug, [{logger, {elogger_console, []}}]}
+ {lager, [
+ {handlers,
+ [
+ {lager_console_backend, [debug,true]}
+ ]}
]},
{sasl, [{errlog_type, all},
{sasl_error_logger, {file, "/var/log/edis.sasl.log"}}]}].
View
@@ -1,11 +1,13 @@
-{deps, [{elog, "\.*", {git, "git://github.com/inaka/elog.git", "master"}},
+{deps, [{lager, "2.0.0", {git, "git@github.com:basho/lager.git", "master"}},
+ {eper, "0.60", {git, "git@github.com:mhald/eper.git", "HEAD"}},
{erldis, "\.*", {git, "git://github.com/inaka/erldis.git", "master"}},
{eleveldb, "\.*", {git, "git://github.com/inaka/eleveldb.git", "master"}},
{hanoidb, "\.*", {git, "git://github.com/basho-labs/hanoidb.git", "master"}}]}.
{require_otp_vsn, "R1[45]"}.
{erl_first_files, ["src/edis_backend.erl", "test/edis_bench.erl"]}.
-{erl_opts, [{src_dirs, ["src", "src/backends", "tests", "test/benchmarks"]},
- {i, "deps/elog/include"},
+{erl_opts, [{parse_transform, lager_transform},
+ {src_dirs, ["src", "src/backends", "tests", "test/benchmarks"]},
+ %{i, "deps/lager/include"},
warn_unused_vars,
warn_export_all,
warn_shadow_vars,
@@ -23,3 +25,6 @@
{xref_checks, [undefined_function_calls]}.
{ct_extra_params,"-no_auto_compile -dir ./test/ebin -logdir logs/ct"}.
{edoc_opts, [{report_missing_types, true}, {source_path, ["src"]}, {report_missing_types, true}, {todo, true}, {packages, false}, {subpackages, false}]}.
+
+
+
@@ -24,7 +24,7 @@
%% ====================================================================
-spec init(string(), non_neg_integer(), [any()]) -> {ok, ref()} | {error, term()}.
init(_Dir, _Index, _Options) ->
- ?WARN("USING PD BACKEND!! This should not be a production environment!~n", []),
+ lager:warn("USING PD BACKEND!! This should not be a production environment!~n", []),
{ok, #ref{}}.
-spec write(ref(), edis_backend:write_actions()) -> ok | {error, term()}.
View
@@ -33,7 +33,7 @@ main(Args) ->
[ConfigFile] -> edis_util:load_config(ConfigFile)
end,
crypto:start(),
- ok = application:start(elog),
+ ok = application:start(lager),
ok = start(),
Pid = erlang:whereis(edis_sup),
Ref = erlang:monitor(process, Pid),
View
@@ -68,18 +68,18 @@ socket({socket_ready, Socket}, State) ->
{ok, {_Ip, Port}} -> Port;
Error -> Error
end,
- ?INFO("New Client: ~p ~n", [PeerPort]),
+ lager:info("New Client: ~p ~n", [PeerPort]),
ok = inet:setopts(Socket, [{active, once}, {packet, line}, binary]),
_ = erlang:process_flag(trap_exit, true), %% We want to know even if it stops normally
{ok, CmdRunner} = edis_command_runner:start_link(Socket),
{next_state, command_start, State#state{socket = Socket,
peerport = PeerPort,
command_runner = CmdRunner}, hibernate};
socket(timeout, State) ->
- ?THROW("Timeout~n", []),
+ lager:alert("Timeout~n", []),
{stop, timeout, State};
socket(Other, State) ->
- ?THROW("Unexpected message: ~p\n", [Other]),
+ lager:alert("Unexpected message: ~p\n", [Other]),
{stop, {unexpected_event, Other}, State}.
%% @hidden
@@ -90,11 +90,11 @@ command_start({data, <<"\n">>}, State) ->
{next_state, command_start, State};
command_start({data, <<"*", N/binary>>}, State) -> %% Unified Request Protocol
{NArgs, "\r\n"} = string:to_integer(binary_to_list(N)),
- ?DEBUG("URP command - ~p args~n",[NArgs]),
+ lager:debug("URP command - ~p args~n",[NArgs]),
{next_state, arg_size, State#state{missing_args = NArgs, command_name = undefined, args = []}};
command_start({data, OldCmd}, State) ->
[Command|Args] = binary:split(OldCmd, [<<" ">>, <<"\r\n">>], [global,trim]),
- ?DEBUG("Old protocol command ~p (~p args)~n",[Command, length(Args)]),
+ lager:debug("Old protocol command ~p (~p args)~n",[Command, length(Args)]),
case edis_command_runner:last_arg(edis_util:upper(Command)) of
inlined ->
ok = edis_command_runner:run(State#state.command_runner, edis_util:upper(Command), Args),
@@ -122,7 +122,7 @@ command_start({data, OldCmd}, State) ->
end
end;
command_start(Event, State) ->
- ?THROW("Unexpected Event: ~p~n", [Event]),
+ lager:alert("Unexpected Event: ~p~n", [Event]),
{stop, {unexpected_event, Event}, State}.
%% @hidden
@@ -135,29 +135,29 @@ arg_size({data, <<"$", N/binary>>}, State) ->
"lenght of next arg expected. ~s received instead", [N])),
{next_state, command_start, State, hibernate};
{ArgSize, _Rest} ->
- ?DEBUG("Arg Size: ~p ~n", [ArgSize]),
+ lager:debug("Arg Size: ~p ~n", [ArgSize]),
{next_state, case State#state.command_name of
undefined -> command_name;
_Command -> argument
end, State#state{next_arg_size = ArgSize, buffer = <<>>}}
end;
arg_size(Event, State) ->
- ?THROW("Unexpected Event: ~p~n", [Event]),
+ lager:alert("Unexpected Event: ~p~n", [Event]),
{stop, {unexpected_event, Event}, State}.
%% @hidden
-spec command_name(term(), state()) -> {next_state, command_start, state(), hibernate} | {next_state, arg_size, state()} | {stop, {unexpected_event, term()}, state()}.
command_name({data, Data}, State = #state{next_arg_size = Size, missing_args = 1}) ->
<<Command:Size/binary, _Rest/binary>> = Data,
- ?DEBUG("Command: ~p ~n", [Command]),
+ lager:debug("Command: ~p ~n", [Command]),
ok = edis_command_runner:run(State#state.command_runner, edis_util:upper(Command), []),
{next_state, command_start, State, hibernate};
command_name({data, Data}, State = #state{next_arg_size = Size, missing_args = MissingArgs}) ->
<<Command:Size/binary, _Rest/binary>> = Data,
- ?DEBUG("Command: ~p ~n", [Command]),
+ lager:debug("Command: ~p ~n", [Command]),
{next_state, arg_size, State#state{command_name = Command, missing_args = MissingArgs - 1}};
command_name(Event, State) ->
- ?THROW("Unexpected Event: ~p~n", [Event]),
+ lager:alert("Unexpected Event: ~p~n", [Event]),
{stop, {unexpected_event, Event}, State}.
%% @hidden
@@ -180,7 +180,7 @@ argument({data, Data}, State = #state{buffer = Buffer,
{next_state, argument, State#state{buffer = NewBuffer}}
end;
argument(Event, State) ->
- ?THROW("Unexpected Event: ~p~n", [Event]),
+ lager:alert("Unexpected Event: ~p~n", [Event]),
{stop, {unexpected_event, Event}, State}.
%% OTHER EVENTS -------------------------------------------------------
@@ -197,19 +197,19 @@ handle_sync_event(Event, _From, StateName, StateData) ->
%% @hidden
-spec handle_info(term(), atom(), state()) -> term().
handle_info({'EXIT', CmdRunner, Reason}, _StateName, State = #state{command_runner = CmdRunner}) ->
- ?DEBUG("Command runner stopped: ~p~n", [Reason]),
+ lager:debug("Command runner stopped: ~p~n", [Reason]),
{stop, Reason, State};
handle_info({tcp, Socket, Bin}, StateName, #state{socket = Socket,
peerport = PeerPort} = StateData) ->
% Flow control: enable forwarding of next TCP message
ok = inet:setopts(Socket, [{active, false}]),
- ?CDEBUG(data, "~p >> ~s", [PeerPort, Bin]),
+ lager:debug("~p >> ~s", [PeerPort, Bin]),
Result = ?MODULE:StateName({data, Bin}, StateData),
ok = inet:setopts(Socket, [{active, once}]),
Result;
handle_info({tcp_closed, Socket}, _StateName, #state{socket = Socket,
peerport = PeerPort} = StateData) ->
- ?DEBUG("Disconnected ~p.~n", [PeerPort]),
+ lager:debug("Disconnected ~p.~n", [PeerPort]),
{stop, normal, StateData};
handle_info(_Info, StateName, StateData) ->
{next_state, StateName, StateData}.
@@ -221,7 +221,7 @@ terminate(normal, _StateName, #state{socket = Socket, command_runner = CmdRunner
(catch gen_tcp:close(Socket)),
ok;
terminate(Reason, _StateName, #state{socket = Socket, command_runner = CmdRunner}) ->
- ?WARN("Terminating client: ~p~n", [Reason]),
+ debug:warn("Terminating client: ~p~n", [Reason]),
edis_command_runner:stop(CmdRunner),
(catch gen_tcp:close(Socket)),
ok.
View
@@ -57,7 +57,7 @@ count_clients() ->
%% @hidden
-spec init([]) -> {ok, {{one_for_one, 5, 10}, [supervisor:child_spec()]}}.
init([]) ->
- ?INFO("Client supervisor initialized (~p managers)~n", [?MANAGERS]),
+ lager:info("Client supervisor initialized (~p managers)~n", [?MANAGERS]),
Managers =
[{list_to_atom("edis-client-mgr-" ++ integer_to_list(I)),
{edis_client_mgr, start_link, [list_to_atom("edis-client-mgr-" ++ integer_to_list(I))]},
@@ -101,17 +101,17 @@ handle_cast({run, Cmd, Args}, State) ->
_:timeout ->
tcp_multi_bulk(undefined, State);
_:invalid_password ->
- ?WARN("Invalid password.~n", []),
+ lager:warn("Invalid password.~n", []),
tcp_err(<<"invalid password">>, State#state{authenticated = false});
_:Error ->
- ?ERROR("Error in db ~p: ~p~n", [State#state.db_index, Error]),
+ debug:error("Error in db ~p: ~p~n", [State#state.db_index, Error]),
tcp_err(parse_error(Cmd, Error), State)
end.
%% @hidden
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
handle_info(#edis_message{} = Message, State = #state{subscriptions = undefined}) ->
- ?WARN("Unexpected message: ~p~n", [Message]),
+ lager:warn("Unexpected message: ~p~n", [Message]),
{noreply, State, hibernate};
handle_info(#edis_message{} = Message, State) ->
{ChannelSet, PatternSet} = State#state.subscriptions,
@@ -139,10 +139,10 @@ handle_info(#edis_command{} = Command, State) ->
Command#edis_command.cmd,
edis_util:join(Command#edis_command.args, <<" ">>)]), State);
handle_info({gen_event_EXIT, _Handler, Reason}, State) ->
- ?INFO("Monitor deactivated. Reason: ~p~n", [Reason]),
+ lager:info("Monitor deactivated. Reason: ~p~n", [Reason]),
{noreply, State, hibernate};
handle_info(Info, State) ->
- ?INFO("Unexpected info: ~p~n", [Info]),
+ lager:info("Unexpected info: ~p~n", [Info]),
{noreply, State, hibernate}.
%% @hidden
@@ -912,22 +912,22 @@ tcp_string(Message, State) ->
%% @private
-spec tcp_send(iodata(), state()) -> {noreply, state(), hibernate} | {stop, normal | {error, term()}, state()}.
tcp_send(Message, State) ->
- ?CDEBUG(data, "~p << ~s~n", [State#state.peerport, Message]),
+ lager:debug("~p << ~s~n", [State#state.peerport, Message]),
try gen_tcp:send(State#state.socket, [Message, "\r\n"]) of
ok ->
{noreply, State, hibernate};
{error, closed} ->
- ?DEBUG("Connection closed~n", []),
+ lager:debug("Connection closed~n", []),
{stop, normal, State};
{error, Error} ->
- ?THROW("Couldn't send msg through TCP~n\tError: ~p~n", [Error]),
+ lager:alert("Couldn't send msg through TCP~n\tError: ~p~n", [Error]),
{stop, {error, Error}, State}
catch
_:{Exception, _} ->
- ?THROW("Couldn't send msg through TCP~n\tError: ~p~n", [Exception]),
+ lager:alert("Couldn't send msg through TCP~n\tError: ~p~n", [Exception]),
{stop, normal, State};
_:Exception ->
- ?THROW("Couldn't send msg through TCP~n\tError: ~p~n", [Exception]),
+ lager:alert("Couldn't send msg through TCP~n\tError: ~p~n", [Exception]),
{stop, normal, State}
end.
View
@@ -21,29 +21,29 @@ set(listener_port_range, {P1, P2}) when is_integer(P1), is_integer(P2), P1 =< P2
ok = application:set_env(edis, listener_port_range, {P1, P2}),
edis_listener_sup:reload();
set(listener_port_range, Param) ->
- ?THROW("Invalid range: ~p~n", [Param]),
+ lager:alert("Invalid range: ~p~n", [Param]),
throw(invalid_param);
set(client_timeout, Timeout) when is_integer(Timeout), Timeout >= 0 ->
ok = application:set_env(edis, client_timeout, Timeout);
set(client_timeout, Param) ->
- ?THROW("Invalid timeout: ~p~n", [Param]),
+ lager:alert("Invalid timeout: ~p~n", [Param]),
throw(invalid_param);
set(databases, Dbs) when is_integer(Dbs), Dbs > 0 ->
ok = application:set_env(edis, databases, Dbs),
edis_db_sup:reload();
set(databases, Param) ->
- ?THROW("Invalid number: ~p~n", [Param]),
+ lager:alert("Invalid number: ~p~n", [Param]),
throw(invalid_param);
set(requirepass, Pass) ->
ok = application:set_env(edis, requirepass, Pass);
set(dir, Dir) when is_binary(Dir) ->
ok = application:set_env(edis, dir, binary_to_list(Dir)),
edis_db_sup:reload();
set(dir, Param) ->
- ?THROW("Invalid dir: ~p~n", [Param]),
+ lager:alert("Invalid dir: ~p~n", [Param]),
throw(invalid_param);
set(Param, Value) ->
- ?THROW("Unsupported param: ~p: ~p~n", [Param, Value]),
+ lager:alert("Unsupported param: ~p: ~p~n", [Param, Value]),
throw(unsupported_param).
%% @doc gets configuration params
@@ -68,9 +68,9 @@ get(Pattern) ->
get(Field, Default) ->
case application:get_env(edis, Field) of
{ok, Value} ->
- ?DEBUG("~p := ~p~n", [Field, Value]),
+ lager:debug("~p := ~p~n", [Field, Value]),
Value;
_ ->
- ?DEBUG("~p := ~p~n", [Field, Default]),
+ lager:debug("~p := ~p~n", [Field, Default]),
Default
end.
Oops, something went wrong.

0 comments on commit f48a329

Please sign in to comment.