You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/09/18 15:13:12 UTC
twig commit: updated refs/heads/master to 9393f4d
Repository: couchdb-twig
Updated Branches:
refs/heads/master ea18f4f63 -> 9393f4d95
Allow facility override in options
Project: http://git-wip-us.apache.org/repos/asf/couchdb-twig/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-twig/commit/9393f4d9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-twig/tree/9393f4d9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-twig/diff/9393f4d9
Branch: refs/heads/master
Commit: 9393f4d957b1054c562da00d8c3d467d88b13a84
Parents: ea18f4f
Author: Robert Newson <rn...@apache.org>
Authored: Wed Aug 19 00:16:30 2015 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Sep 18 14:04:32 2015 +0100
----------------------------------------------------------------------
src/twig.erl | 21 +++++++++++++++------
src/twig_event_handler.erl | 22 +++++++++++++++-------
src/twig_int.hrl | 2 +-
3 files changed, 31 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/9393f4d9/src/twig.erl
----------------------------------------------------------------------
diff --git a/src/twig.erl b/src/twig.erl
index 488dd28..affea40 100644
--- a/src/twig.erl
+++ b/src/twig.erl
@@ -54,29 +54,38 @@ log(LevelAtom, String) ->
log(LevelAtom, Format, Data) ->
log(LevelAtom, Format, Data, []).
-log(LevelAtom, Format, Data, _Options) ->
+log(LevelAtom, Format, Data, Options) ->
%% TODO do something useful with options
Level = twig_util:level(LevelAtom),
+ Facility = get_facility(Options),
case application:get_env(twig, level) of
{ok, Threshold} when Level =< Threshold ->
- send_message(Level, Format, Data);
+ send_message(Level, Facility, Format, Data);
undefined when Level =< ?LEVEL_INFO ->
- send_message(Level, Format, Data);
+ send_message(Level, Facility, Format, Data);
_ ->
ok
end.
%% internal
-send_message(Level, Format, Data) ->
- gen_event:sync_notify(error_logger, format(Level, Format, Data)).
+send_message(Level, Facility, Format, Data) ->
+ gen_event:sync_notify(error_logger, format(Level, Facility, Format, Data)).
-format(Level, Format, Data) ->
+format(Level, Facility, Format, Data) ->
%% TODO truncate large messages
#twig{
level = Level,
+ facility = Facility,
msg = iolist_to_binary(twig_util:format(Format, Data)),
msgid = erlang:get(nonce),
pid = self()
}.
+get_facility(Options) ->
+ case proplists:get_value(facility, Options) of
+ undefined ->
+ undefined;
+ Facility ->
+ twig_util:facility(Facility)
+ end.
http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/9393f4d9/src/twig_event_handler.erl
----------------------------------------------------------------------
diff --git a/src/twig_event_handler.erl b/src/twig_event_handler.erl
index d7b691b..baa0f65 100644
--- a/src/twig_event_handler.erl
+++ b/src/twig_event_handler.erl
@@ -37,8 +37,12 @@ init([]) ->
{ok, ok, State} = handle_call(load_config, #state{socket=Socket}),
{ok, State}.
-handle_event(#twig{level=Level, msgid=MsgId, msg=Msg, pid=Pid}, State) ->
- write(Level, MsgId, Msg, Pid, State),
+handle_event(#twig{level=Level, facility=undefined, msgid=MsgId, msg=Msg, pid=Pid},
+ #state{facility = Facility} = State) ->
+ write(Level, Facility, MsgId, Msg, Pid, State),
+ {ok, State};
+handle_event(#twig{level=Level, facility=Facility, msgid=MsgId, msg=Msg, pid=Pid}, State) ->
+ write(Level, Facility, MsgId, Msg, Pid, State),
{ok, State};
% OTP standard events
@@ -90,12 +94,16 @@ terminate(_Reason, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-write(Level, undefined, Msg, Pid, State) ->
- write(Level, "--------", Msg, Pid, State);
-write(Level, MsgId, Msg, Pid, State) when is_list(Msg); is_binary(Msg) ->
- #state{facility=Facil, appid=App, hostname=Hostname, host=Host, port=Port,
+write(Level, MsgId, Msg, Pid, State) ->
+ #state{facility = Facility} = State,
+ write(Level, Facility, MsgId, Msg, Pid, State).
+
+write(Level, Facility, undefined, Msg, Pid, State) ->
+ write(Level, Facility, "--------", Msg, Pid, State);
+write(Level, Facility, MsgId, Msg, Pid, State) when is_list(Msg); is_binary(Msg) ->
+ #state{appid=App, hostname=Hostname, host=Host, port=Port,
socket=Socket} = State,
- Pre = io_lib:format("<~B>~B ~s ~s ~s ~p ~s - ", [Facil bor Level,
+ Pre = io_lib:format("<~B>~B ~s ~s ~s ~p ~s - ", [Facility bor Level,
?SYSLOG_VERSION, twig_util:iso8601_timestamp(), Hostname, App, Pid,
MsgId]),
send(Socket, Host, Port, [Pre, Msg, $\n]).
http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/9393f4d9/src/twig_int.hrl
----------------------------------------------------------------------
diff --git a/src/twig_int.hrl b/src/twig_int.hrl
index 81ef8b5..82091af 100644
--- a/src/twig_int.hrl
+++ b/src/twig_int.hrl
@@ -21,4 +21,4 @@
-define(LEVEL_ALERT, 1).
-define(LEVEL_EMERG, 0).
--record(twig, {level, msgid, msg, pid}).
+-record(twig, {level, facility, msgid, msg, pid}).