added possibility to log in file
This commit is contained in:
parent
e5f2652ae6
commit
ad4ccadc15
3 changed files with 26 additions and 16 deletions
|
@ -7,7 +7,8 @@
|
|||
|
||||
-record(ate, {
|
||||
server_messages = 0,
|
||||
client_messages = 0
|
||||
client_messages = 0,
|
||||
stats = []
|
||||
}).
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
|
@ -29,7 +30,8 @@ start_link() ->
|
|||
init(_Args) ->
|
||||
St = #ate{
|
||||
server_messages = 0,
|
||||
client_messages = 0
|
||||
client_messages = 0,
|
||||
stats = []
|
||||
},
|
||||
{ok, St}.
|
||||
|
||||
|
@ -37,23 +39,28 @@ handle_cast({add_one, Type}, St) ->
|
|||
case Type of
|
||||
server -> NewSt = #ate {
|
||||
server_messages = St#ate.server_messages + 1,
|
||||
client_messages = St#ate.client_messages
|
||||
client_messages = St#ate.client_messages,
|
||||
stats = St#ate.stats
|
||||
};
|
||||
client -> NewSt = #ate {
|
||||
server_messages = St#ate.server_messages,
|
||||
client_messages = St#ate.client_messages + 1
|
||||
client_messages = St#ate.client_messages + 1,
|
||||
stats = St#ate.stats
|
||||
}
|
||||
end,
|
||||
{noreply, NewSt};
|
||||
|
||||
handle_cast(print, St) ->
|
||||
CS = length(ggs_coordinator:get_all_players()),
|
||||
io:fwrite("CS:~w | CM:~w | SM:~w~n", [CS, St#ate.server_messages, St#ate.client_messages]),
|
||||
S = lists:concat([CS,";",St#ate.server_messages,";",St#ate.client_messages]),
|
||||
log("/tmp/ggs-log.csv", S),
|
||||
io:fwrite("CS:~w | CM:~w | SM:~w |~n", [CS, St#ate.server_messages, St#ate.client_messages]),
|
||||
{noreply, St};
|
||||
|
||||
handle_cast(tick, _St) ->
|
||||
handle_cast(tick, St) ->
|
||||
NewSt = #ate { server_messages = 0,
|
||||
client_messages = 0 },
|
||||
client_messages = 0,
|
||||
stats = St#ate.stats },
|
||||
{noreply, NewSt}.
|
||||
|
||||
|
||||
|
@ -62,3 +69,6 @@ handle_call(_Request, _From, St) -> {stop, unimplemented, St}.
|
|||
handle_info(_Info, St) -> {stop, unimplemented, St}.
|
||||
terminate(_Reason, _St) -> ok.
|
||||
code_change(_OldVsn, St, _Extra) -> {ok, St}.
|
||||
|
||||
log(FileName, Data) ->
|
||||
file:write_file(FileName, Data ++ "\n", [append]).
|
||||
|
|
Reference in a new issue