Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
use Vagabond's syslog backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Elverkilde committed Aug 13, 2013
1 parent c54eb4a commit 0d3e562
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{erl_first_files, ["src/elli_handler.erl"]}.
{erl_opts, [debug_info]}.
{deps, [
{syslog, "1.0", {git, "git://github.com/wooga/erlang_syslog.git", "master"}}
{syslog, "1.0", {git, "git@github.com:Vagabond/erlang-syslog.git", "master"}}
]}.
10 changes: 0 additions & 10 deletions src/elli_access_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ handle_event(client_timeout, [_When], _Config) ->
handle_event(elli_startup, [], Config) ->
MsgOpts = msg_opts(Config),

case whereis(name(Config)) of
undefined ->
{ok, _Pid} = syslog:start_link(name(Config),
ip(Config),
port(Config));
Pid when is_pid(Pid) ->
ok
end,

{ok, _} = elli_access_log_server:start_link(name(Config), MsgOpts),
ok;

Expand All @@ -130,7 +121,6 @@ msg_opts(Config) ->
msg_opts_with_defaults(MsgOpts) ->
{ok, Host} = inet:gethostname(),
Defaults = [{host, Host},
{ident, node()},
{facility, local0}],

lists:ukeymerge(1, lists:keysort(1, MsgOpts),
Expand Down
23 changes: 20 additions & 3 deletions src/elli_access_log_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-record(state, {name, msg_opts}).
-record(state, {name, msg_opts, log}).

%%
%% API
Expand All @@ -28,8 +28,14 @@ init([Name, MsgOpts]) ->
Name = ets:new(Name, [ordered_set, named_table, public,
{write_concurrency, true}]),

syslog:start(),
{ok, Log} = syslog:open(ident(MsgOpts),
[],
facility(MsgOpts)),


erlang:send_after(1000, self(), flush),
{ok, #state{name = Name, msg_opts = MsgOpts}}.
{ok, #state{name = Name, msg_opts = MsgOpts, log = Log}}.


handle_call(_Request, _From, State) ->
Expand All @@ -45,7 +51,10 @@ handle_info(flush, State) ->
{Msg, State#state.msg_opts}
end, flush(State#state.name)),

syslog:multi_send(State#state.name, SyslogMessages),
lists:map(fun ({Message, MsgOpt}) ->
syslog:log(State#state.log, info, Message)
end, SyslogMessages),

{noreply, State}.

terminate(_Reason, _State) ->
Expand Down Expand Up @@ -74,3 +83,11 @@ flush_before(Now, Name, Key, Acc) when Now >= Key ->
flush_before(Now, Name, ets:next(Name, Key), [Value | Acc]);
flush_before(_Now, _Name, _Key, Acc) ->
Acc.


%%
%% HELPERS
%%

facility(Config) -> proplists:get_value(facility, Config, local0).
ident(Config) -> proplists:get_value(ident, Config, atom_to_list(node())).

0 comments on commit 0d3e562

Please sign in to comment.