Skip to content

Commit

Permalink
WHISTLE-945: use the log macros
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Feb 9, 2012
1 parent 1f882a3 commit 19f4382
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/whistle-1.0.0/src/wh_timer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
%%%-------------------------------------------------------------------
-module(wh_timer).

-include("../include/wh_log.hrl").

-behaviour(gen_server).

%% API
-export([start_link/0, start/0, start/1, tick/0, tick/1, stop/0, stop/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
terminate/2, code_change/3]).

-define(SERVER, ?MODULE).

Expand Down Expand Up @@ -93,18 +95,18 @@ handle_call({start, Msg}, {Pid, _}, S) ->
{reply, ok, dict:store(Pid, {erlang:now(), [D]}, S), hibernate};
handle_call({tick, Msg}, {Pid, _}, S) ->
case dict:find(Pid, S) of
{ok, {Start, L}} ->
{reply, ok, dict:store(Pid, {Start, [io_lib:format("TS_TIMER(~p): ~10.w micros: Tick-~p~n", [Pid, timer:now_diff(erlang:now(), Start), Msg])
| L]}, S), hibernate};
error -> {reply, {error, not_started}, S}
{ok, {Start, L}} ->
{reply, ok, dict:store(Pid, {Start, [io_lib:format("TS_TIMER(~p): ~10.w micros: Tick-~p~n", [Pid, timer:now_diff(erlang:now(), Start), Msg])
| L]}, S), hibernate};
error -> {reply, {error, not_started}, S}
end;
handle_call({stop, Msg}, {Pid, _}, S) ->
case dict:find(Pid, S) of
{ok, {Start, L}} ->
lists:foreach(fun(D) -> io:format(D, []) end, lists:reverse(L)),
io:format("TS_TIMER(~p): ~10.w: End: ~p~n", [Pid, timer:now_diff(erlang:now(), Start), Msg]),
{reply, ok, dict:erase(Pid, S), hibernate};
error -> {reply, {error, not_started}, S}
{ok, {Start, L}} ->
lists:foreach(fun(D) -> io:format(D, []) end, lists:reverse(L)),
io:format("TS_TIMER(~p): ~10.w: End: ~p~n", [Pid, timer:now_diff(erlang:now(), Start), Msg]),
{reply, ok, dict:erase(Pid, S), hibernate};
error -> {reply, {error, not_started}, S}
end.

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -134,7 +136,7 @@ handle_info({'DOWN', _, process, Pid, _}, State) ->
_ = handle_call({stop, "Stop"}, {Pid, ok}, State),
{noreply, dict:erase(Pid, State), hibernate};
handle_info(_Info, State) ->
logger:format_log(info, "WH_TIMER(~p): unhandled info: ~p~n", [self(), _Info]),
?LOG(info, "WH_TIMER(~p): unhandled info: ~p~n", [self(), _Info]),
{noreply, State}.

%%--------------------------------------------------------------------
Expand Down

0 comments on commit 19f4382

Please sign in to comment.