You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/03 23:12:26 UTC

[12/29] twig commit: updated refs/heads/import to 2d56280

Record nonce as MSGID and self() as PROCID


Project: http://git-wip-us.apache.org/repos/asf/couchdb-twig/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-twig/commit/ebd486dc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-twig/tree/ebd486dc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-twig/diff/ebd486dc

Branch: refs/heads/import
Commit: ebd486dcdaa943c934dc495e7ed16519f5473bf9
Parents: edf6cc4
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Tue Mar 8 15:58:32 2011 -0500
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Tue Mar 8 15:58:32 2011 -0500

----------------------------------------------------------------------
 src/twig.erl               |  7 ++++++-
 src/twig_event_handler.erl | 27 +++++++++++++++------------
 src/twig_int.hrl           |  1 +
 3 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/ebd486dc/src/twig.erl
----------------------------------------------------------------------
diff --git a/src/twig.erl b/src/twig.erl
index 15e303b..191c25b 100644
--- a/src/twig.erl
+++ b/src/twig.erl
@@ -44,5 +44,10 @@ send_message(Level, Format, Data) ->
 
 format(Level, Format, Data) ->
     %% TODO truncate large messages
-    {twig, Level, iolist_to_binary(io_lib:format(Format, Data))}.
+    #twig{
+        level = Level,
+        msg = iolist_to_binary(io_lib:format(Format, Data)),
+        msgid = erlang:get(nonce),
+        pid = self()
+    }.
 

http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/ebd486dc/src/twig_event_handler.erl
----------------------------------------------------------------------
diff --git a/src/twig_event_handler.erl b/src/twig_event_handler.erl
index d20a5eb..caf6b5f 100644
--- a/src/twig_event_handler.erl
+++ b/src/twig_event_handler.erl
@@ -35,8 +35,8 @@ init([]) ->
     {ok, ok, State} = handle_call(load_config, #state{socket=Socket}),
     {ok, State}.
 
-handle_event({twig, Level, Msg}, State) ->
-    write(Level, Msg, State),
+handle_event(#twig{level=Level, msgid=MsgId, msg=Msg, pid=Pid}, State) ->
+    write(Level, MsgId, Msg, Pid, State),
     {ok, State};
 
 % OTP standard events
@@ -47,7 +47,7 @@ handle_event({Class, _GL, {Pid, Format, Args}}, #state{level=Max} = State) ->
         Level when Level > Max ->
             {ok, State};
         Level ->
-            write(Level, message(Pid, Format, Args), State),
+            write(Level, undefined, message(Pid, Format, Args), Pid, State),
             {ok, State}
     end;
 
@@ -95,21 +95,24 @@ get_env(Key, Default) ->
             Default
     end.
 
-write(_, _, #state{host=undefined}) ->
+write(_, _, _, _, #state{host=undefined}) ->
     ok;
-write(Level, Msg, State) when is_list(Msg); is_binary(Msg) ->
+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,
-        socket=Socket, os_pid=OsPid} = State,
-     Pre = io_lib:format("<~B>~B ~s ~s ~s ~s - - ", [Facil bor Level,
-        ?SYSLOG_VERSION, twig_util:iso8601_timestamp(), Hostname, App, OsPid]),
+        socket=Socket} = State,
+     Pre = io_lib:format("<~B>~B ~s ~s ~s ~s ~s - ", [Facil bor Level,
+        ?SYSLOG_VERSION, twig_util:iso8601_timestamp(), Hostname, App, Pid,
+        MsgId]),
     %% TODO truncate large messages
      gen_udp:send(Socket, Host, Port, [Pre, Msg, $\n]);
-write(Level, {Format0, Args0}, State) ->
+write(Level, MsgId, {Format0, Args0}, Pid, State) ->
     #state{facility=Facil, appid=App, hostname=Hostname, host=Host, port=Port,
-        socket=Socket, os_pid=OsPid} = State,
-    Format = "<~B>~B ~s ~s ~s ~s - - " ++ Format0 ++ "\n",
+        socket=Socket} = State,
+    Format = "<~B>~B ~s ~s ~s ~s ~s - " ++ Format0 ++ "\n",
     Args = [Facil bor Level, ?SYSLOG_VERSION, twig_util:iso8601_timestamp(),
-        Hostname, App, OsPid | Args0],
+        Hostname, App, Pid, MsgId | Args0],
     %% TODO truncate large messages
     Packet = io_lib:format(Format, Args),
     gen_udp:send(Socket, Host, Port, Packet).

http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/ebd486dc/src/twig_int.hrl
----------------------------------------------------------------------
diff --git a/src/twig_int.hrl b/src/twig_int.hrl
index 27f66ad..81ef8b5 100644
--- a/src/twig_int.hrl
+++ b/src/twig_int.hrl
@@ -21,3 +21,4 @@
 -define(LEVEL_ALERT, 1).
 -define(LEVEL_EMERG, 0).
 
+-record(twig, {level, msgid, msg, pid}).