Permalink
Browse files

Use lager as the logging application.

Replace log.hrl and everything pertaining to it. We now use the lager
application for everything.
  • Loading branch information...
1 parent ad1bb99 commit ea5550bfedc8c237738d0f82a2afd3eb4c3f7870 @jlouis committed Dec 10, 2011
View
@@ -1,12 +0,0 @@
--define(INFO(T), error_logger:info_report(T)).
--define(WARN(T), error_logger:warning_report(
- [process_info(self(), current_function), {line, ?LINE} | T])).
--define(ERR(T), error_logger:error_report(
- [process_info(self(), current_function), {line, ?LINE} | T])).
-
--define(DEBUG(Format, Args), io:format("D(~p:~p:~p) : "++Format++"~n",
- [self(),?MODULE,?LINE]++Args)).
--define(DEBUGP(Args), io:format("D(~p:~p:~p) : ~p~n",
- [self(),?MODULE,?LINE, Args])).
--define(NOTIFY(M), etorrent_event:notify(M)).
-
View
@@ -1,21 +0,0 @@
-{erl_opts, [
- %% bin_opt_info,
- warn_format,
- warn_export_all,
- warn_export_vars,
- warn_obsolete_guard,
- %% warn_unused_import,
- warn_bif_clash,
- %% warn_missing_spec,
- warn_untyped_record,
- debug_info]}.
-
-{cover_enabled, true}.
-
-{dialyzer_opts, [{warnings, [error_handling,
- race_conditions,
- behaviours]}]}.
-
-{xref_checks, [undefined_function_calls,
- locals_not_used,
- exports_not_used]}.
View
@@ -29,7 +29,7 @@
etorrent_upnp_net,
etorrent_upnp_sup
]},
- {applications, [kernel, stdlib, cowboy, crypto, public_key, sasl, gproc,
+ {applications, [kernel, stdlib, lager, cowboy, crypto, public_key, sasl, gproc,
rlimit, ssl, lhttpc]},
{mod, {etorrent_app, []}},
{env, []}
View
@@ -8,7 +8,6 @@
%% @end
-module(etorrent).
--include("log.hrl").
%% API
%% Query
@@ -51,10 +50,11 @@ start(Filename) when is_list(Filename) ->
%% @end
start(Filename, {Ref, Pid})
when is_list(Filename), is_reference(Ref), is_pid(Pid) ->
- start(Filename, fun() ->
- ?INFO([completing_torrent_callback, Filename]),
- Pid ! {Ref, done}
- end);
+ start(Filename,
+ fun() ->
+ lager:info("Completing torrent callback: ~s", [Filename]),
+ Pid ! {Ref, done}
+ end);
start(Filename, CallBack) when is_list(Filename), is_function(CallBack, 0) ->
etorrent_ctl:start(Filename, CallBack).
@@ -9,7 +9,6 @@
-behaviour(gen_server).
--include("log.hrl").
%% API
-export([start_link/2]).
@@ -53,7 +52,9 @@ handle_info(timeout, #state { our_peer_id = PeerId } = S) ->
{error, closed} -> ok;
{error, econnaborted} -> ok;
{error, enotconn} -> ok;
- {error, E} -> ?WARN([{error, E}]), ok
+ {error, E} ->
+ lager:info("TCP accept error: ~p", [E]),
+ ok
end,
{stop, normal, S}.
@@ -86,8 +87,8 @@ handshake(Socket, PeerId) ->
throw:{error, _Reason} ->
gen_tcp:close(Socket),
ok;
- throw:{bad_peer, HisPId} ->
- ?INFO([peer_id_is_bad, HisPId]),
+ throw:{bad_peer, PeerPid} ->
+ lager:info("Bad Peer: ~p", [PeerPid]),
gen_tcp:close(Socket),
ok
end.
@@ -9,7 +9,6 @@
-include_lib("eunit/include/eunit.hrl").
-endif.
--include("log.hrl").
%% API
-export([allowed_fast/4]).
@@ -3,7 +3,6 @@
%% @end
-module(etorrent_callback_handler).
--include("log.hrl").
-behaviour(gen_event).
%% API
-export([add_handler/0, delete_handler/0]).
@@ -84,7 +83,7 @@ handle_call({install_callbacks, TorrentPid, IH, CBPropList},
{ok, ok, S#state { table = NewT,
monitors = NewM }};
handle_call(Request, State) ->
- ?WARN([unknown_request, Request]),
+ lager:error("Unknown handle_call event: ~p", [Request]),
Reply = ok,
{ok, Reply, State}.
@@ -116,7 +115,8 @@ perform_callback({value, CBs}) ->
try CompFun ()
catch
ErrType:Error ->
- ?ERR([callback_error, ErrType, Error])
+ lager:error("Callback error: ~p, ~p",
+ [ErrType, Error])
end
end),
ok.
View
@@ -14,7 +14,6 @@
-behaviour(gen_server).
-include("rate_mgr.hrl").
--include("log.hrl").
%% API
-export([start_link/0, perform_rechoke/0, monitor/1]).
@@ -316,7 +315,7 @@ handle_call({monitor, Pid}, _From, S) ->
perform_rechoke(),
{reply, ok, S#state { opt_unchoke_chain = NewChain }};
handle_call(Request, _From, State) ->
- ?ERR([unknown_peer_group_call, Request]),
+ lager:error([unknown_peer_group_call, Request]),
Reply = ok,
{reply, Reply, State}.
@@ -346,7 +345,7 @@ handle_info({'DOWN', _Ref, process, Pid, _Reason}, S) ->
rechoke(NewChain),
{noreply, S#state { opt_unchoke_chain = NewChain }};
handle_info(Info, State) ->
- ?INFO([unknown_info_msg, ?MODULE, Info]),
+ lager:info([unknown_info_msg, ?MODULE, Info]),
{noreply, State}.
%% @private
@@ -6,7 +6,6 @@
-module(etorrent_counters).
-behaviour(gen_server).
--include("log.hrl").
%% API
-export([start_link/0, next/1, obtain_peer_slot/0, slots_left/0]).
@@ -84,10 +83,7 @@ handle_cast(_Msg, State) ->
%% @private
handle_info({'DOWN', _Ref, process, _Pid, _Reason}, S) ->
K = ets:update_counter(etorrent_counters, peer_slots, {2, -1, 0, 0}),
- if
- K >= 0 -> ok;
- true -> ?ERR([counter_negative, K])
- end,
+ true = K >= 0, % Assert the state of the counter
{noreply, S};
handle_info(_Info, State) ->
{noreply, State}.
@@ -1,6 +1,5 @@
-module(etorrent_cowboy_handler).
--include("log.hrl").
-export([init/3, handle/2, terminate/2]).
View
@@ -9,7 +9,6 @@
-module(etorrent_ctl).
-behaviour(gen_server).
--include("log.hrl").
-export([start_link/1,
@@ -79,7 +78,7 @@ handle_cast({stop, F}, S) ->
%% @private
handle_call({start, F, CallBack}, _From, S) ->
- ?INFO([starting, F]),
+ lager:info("Starting torrent in file ~s", [F]),
case load_torrent(F) of
duplicate -> {reply, duplicate, S};
{ok, Torrent} ->
@@ -95,7 +94,7 @@ handle_call({start, F, CallBack}, _From, S) ->
{reply, Err, S}
end;
{error, Reason} ->
- ?INFO([malformed_torrent_file, F]),
+ lager:info("Malformed torrent file ~s, error: ~p", [F, Reason]),
etorrent_event:notify({malformed_torrent_file, F}),
{reply, {error, Reason}, S}
end;
@@ -107,7 +106,7 @@ handle_call(_A, _B, S) ->
%% @private
handle_info(Info, State) ->
- ?WARN([unknown_info, Info]),
+ lager:error("Unknown handle_info event: ~p", [Info]),
{noreply, State}.
%% @private
@@ -121,20 +120,20 @@ code_change(_OldVsn, State, _Extra) ->
%% =======================================================================
stop_torrent(F) ->
- ?INFO([stopping, F]),
+ lager:info("Stopping torrent in file ~s", [F]),
case etorrent_table:get_torrent({filename, F}) of
- not_found -> ok; % Was already removed, it is ok.
- {value, PL} ->
- TorrentIH = proplists:get_value(info_hash, PL),
- etorrent_torrent_pool:terminate_child(TorrentIH),
- ok
+ not_found -> ok; % Was already removed, it is ok.
+ {value, PL} ->
+ TorrentIH = proplists:get_value(info_hash, PL),
+ etorrent_torrent_pool:terminate_child(TorrentIH),
+ ok
end.
stop_all() ->
PLS = etorrent_table:all_torrents(),
[begin
- F = proplists:get_value(filename, PL),
- stop_torrent(F)
+ F = proplists:get_value(filename, PL),
+ stop_torrent(F)
end || PL <- PLS].
-spec load_torrent(string()) -> duplicate
@@ -13,7 +13,6 @@
-module(etorrent_fast_resume).
-behaviour(gen_server).
--include("log.hrl").
%% API
-export([start_link/0,
@@ -4,7 +4,6 @@
%% @end
-module(etorrent_file_logger).
--include("log.hrl").
-behaviour(gen_event).
@@ -84,7 +83,9 @@ handle_info(_, State) ->
terminate(_, State) ->
case file:close(State#state.cur_fd) of
ok -> State;
- {error, R} -> ?WARN([cant_close_file,{reason, R}]), State
+ {error, R} ->
+ lager:warning("Can't close file: ~p", [R]),
+ State
end.
%% @private
View
@@ -11,7 +11,6 @@
%% @end
-module(etorrent_http).
--include("log.hrl").
-include("etorrent_version.hrl").
%% API
-export([request/1, build_encoded_form_rfc1738/1, mk_header/1]).
@@ -7,7 +7,6 @@
%% @todo This module is missing some API-calls. They are in other modules.
-module(etorrent_memory_logger).
--include("log.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
-behaviour(gen_event).
@@ -5,7 +5,6 @@
-module(etorrent_mktorrent).
-include_lib("kernel/include/file.hrl").
--include("log.hrl").
%% API
-export([create/3, create/4]).
@@ -13,7 +13,6 @@
-behaviour(gen_server).
-include("etorrent_rate.hrl").
--include("log.hrl").
%% API
-export([start_link/7,
@@ -375,7 +374,7 @@ handle_cast(stop, S) ->
{stop, normal, S};
handle_cast(Msg, State) ->
- ?WARN([unknown_msg, Msg]),
+ lager:error("Unknown handle_cast: ~p", [Msg]),
{noreply, State}.
@@ -452,11 +451,11 @@ handle_info({download, Update}, State) ->
{noreply, NewState};
handle_info({tcp, _, _}, State) ->
- ?ERR([wrong_controller]),
+ lager:error("Detected wrong controller for TCP socket"),
{noreply, State};
handle_info(Info, State) ->
- ?WARN([unknown_msg, Info]),
+ lager:error("Unkonwn handle_info: ~p", [Info]),
{noreply, State}.
%% @private
@@ -465,7 +464,7 @@ terminate(_Reason, _S) ->
%% @private
handle_call(Request, _From, State) ->
- ?WARN([unknown_handle_call, Request]),
+ lager:error("Unknown handle_call: ~p", [Request]),
{noreply, State}.
%% @private
@@ -614,11 +613,14 @@ handle_message({cancel, Index, Offset, Length}, State) ->
handle_message({suggest, Piece}, State) ->
#state{config=Config} = State,
PeerID = etorrent_peerconf:remoteid(Config),
- ?INFO([{peer_id, PeerID}, {suggest, Piece}]),
+ lager:info(
+ "Peer ~p suggested piece ~B, but no support is currently available",
+ [PeerID, Piece]),
{ok, State};
handle_message({have, Piece}, State) ->
- #state{torrent_id=TorrentID, send_pid=SendPid, download=Download, remote=Remote, local=Local} = State,
+ #state{torrent_id=TorrentID, send_pid=SendPid,
+ download=Download, remote=Remote, local=Local} = State,
TmpRemote = etorrent_peerstate:hasone(Piece, Remote),
Pieceset = etorrent_peerstate:pieces(TmpRemote),
%% TODO - see etorrent_peerstate:haspieces/1
@@ -695,7 +697,7 @@ handle_message({extended, 0, _Data}, State) ->
{ok, State};
handle_message(Unknown, State) ->
- ?WARN([unknown_message, Unknown]),
+ lager:error("Unknown handle_message: ~p", [Unknown]),
{stop, normal, State}.
Oops, something went wrong.

0 comments on commit ea5550b

Please sign in to comment.