Skip to content

Commit

Permalink
Not working yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmeta committed Feb 26, 2012
1 parent 7b12673 commit 9df527a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion apps/access_log/src/access_log_handler.erl
Expand Up @@ -5,8 +5,28 @@ init({tcp, http}, Req, _Opts) ->
{ok, Req, undefined_state}.

handle(Req, State) ->
{ok, Reply} = cowboy_http_req:reply(200, [], <<"Hello World!">>, Req),
{ok, Reply} = cowboy_http_req:reply(200, [], <<"Logged this to console">>, Req),
{ok, Reply, State}.

terminate(_Req, _State) ->
ok.

access_log({PeerAddr, DateTime, RequestLine, HttpCode, ContentLength}) ->
io:format("~s - - [~s] \"~s\" ~p ~p~n", [PeerAddr, DateTime, RequestLine, HttpCode, ContentLength]);
access_log(Req) ->
{PeerAddr, _} = cowboy_http_req:peer_addr(Req),
{{Ye,Mo,Da},{Ho,Mi,Se}} = erlang:localtime(),
DateTime = io_lib:format("~2..0B/~s/~4..0B:~2..0B:~2..0B:~2..0B", [Da,month_as_text(Mo),Ye,Ho,Mi,Se]).

month_as_text(1) -> "jan";
month_as_text(2) -> "feb";
month_as_text(3) -> "mar";
month_as_text(4) -> "apr";
month_as_text(5) -> "may";
month_as_text(6) -> "jun";
month_as_text(7) -> "jul";
month_as_text(8) -> "aug";
month_as_text(9) -> "sep";
month_as_text(10) -> "oct";
month_as_text(11) -> "nov";
month_as_text(12) -> "dec".

0 comments on commit 9df527a

Please sign in to comment.