Browse Source

Improve logs.

Roberto Ostinelli 3 years ago
parent
commit
e26cf133bc
6 changed files with 40 additions and 40 deletions
  1. 6 6
      src/syn_backbone.erl
  2. 4 4
      src/syn_event_handler.erl
  3. 11 11
      src/syn_gen_scope.erl
  4. 6 6
      src/syn_groups.erl
  5. 12 12
      src/syn_registry.erl
  6. 1 1
      src/syn_sup.erl

+ 6 - 6
src/syn_backbone.erl

@@ -54,7 +54,7 @@ create_tables_for_scope(Scope) ->
 save_process_name(Key, ProcessName) ->
     true = ets:insert(syn_process_names, {Key, ProcessName}).
 
--spec get_process_name(Key :: any()) ->  ProcessName :: atom().
+-spec get_process_name(Key :: any()) -> ProcessName :: atom().
 get_process_name(Key) ->
     case ets:lookup(syn_process_names, Key) of
         [{_, ProcessName}] -> ProcessName;
@@ -98,7 +98,7 @@ init([]) ->
     {stop, Reason :: any(), Reply :: any(), State :: map()} |
     {stop, Reason :: any(), State :: map()}.
 handle_call({create_tables_for_scope, Scope}, _From, State) ->
-    error_logger:info_msg("SYN[~s] Creating tables for scope '~s'", [node(), Scope]),
+    error_logger:info_msg("SYN[~s] Creating tables for scope '~s'", [?MODULE, Scope]),
     ensure_table_exists(set, syn_registry_by_name, Scope),
     ensure_table_exists(bag, syn_registry_by_pid, Scope),
     ensure_table_exists(ordered_set, syn_groups_by_name, Scope),
@@ -106,7 +106,7 @@ handle_call({create_tables_for_scope, Scope}, _From, State) ->
     {reply, ok, State};
 
 handle_call(Request, From, State) ->
-    error_logger:warning_msg("SYN[~s] Received from ~p an unknown call message: ~p", [node(), From, Request]),
+    error_logger:warning_msg("SYN[~s] Received from ~p an unknown call message: ~p", [?MODULE, From, Request]),
     {reply, undefined, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -117,7 +117,7 @@ handle_call(Request, From, State) ->
     {noreply, State :: map(), Timeout :: non_neg_integer()} |
     {stop, Reason :: any(), State :: map()}.
 handle_cast(Msg, State) ->
-    error_logger:warning_msg("SYN[~s] Received an unknown cast message: ~p", [node(), Msg]),
+    error_logger:warning_msg("SYN[~s] Received an unknown cast message: ~p", [?MODULE, Msg]),
     {noreply, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -128,7 +128,7 @@ handle_cast(Msg, State) ->
     {noreply, State :: map(), Timeout :: non_neg_integer()} |
     {stop, Reason :: any(), State :: map()}.
 handle_info(Info, State) ->
-    error_logger:warning_msg("SYN[~s] Received an unknown info message: ~p", [node(), Info]),
+    error_logger:warning_msg("SYN[~s] Received an unknown info message: ~p", [?MODULE, Info]),
     {noreply, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -136,7 +136,7 @@ handle_info(Info, State) ->
 %% ----------------------------------------------------------------------------------------------------------
 -spec terminate(Reason :: any(), State :: map()) -> terminated.
 terminate(Reason, _State) ->
-    error_logger:info_msg("SYN[~s] Terminating with reason: ~p", [node(), Reason]),
+    error_logger:info_msg("SYN[~s] Terminating with reason: ~p", [?MODULE, Reason]),
     %% return
     terminated.
 

+ 4 - 4
src/syn_event_handler.erl

@@ -106,8 +106,8 @@ call_event_handler(CallbackMethod, Args) ->
             try apply(CustomEventHandler, CallbackMethod, Args)
             catch Class:Reason:Stacktrace ->
                 error_logger:error_msg(
-                    "Syn(~p): Error ~p:~p in custom handler ~p: ~p",
-                    [node(), Class, Reason, CallbackMethod, Stacktrace]
+                    "SYN[~s] Error ~p:~p in custom handler ~p: ~p",
+                    [?MODULE, Class, Reason, CallbackMethod, Stacktrace]
                 )
             end;
 
@@ -131,8 +131,8 @@ do_resolve_registry_conflict(Scope, Name, {Pid1, Meta1, Time1}, {Pid2, Meta2, Ti
 
             catch Class:Reason ->
                 error_logger:error_msg(
-                    "Syn(~p): Error ~p in custom handler resolve_registry_conflict: ~p",
-                    [node(), Class, Reason]
+                    "SYN[~s] Error ~p in custom handler resolve_registry_conflict: ~p",
+                    [?MODULE, Class, Reason]
                 ),
                 undefined
             end;

+ 11 - 11
src/syn_gen_scope.erl

@@ -205,8 +205,8 @@ handle_info({'3.0', discover, RemoteScopePid}, #state{
     nodes_map = NodesMap
 } = State) ->
     RemoteScopeNode = node(RemoteScopePid),
-    error_logger:info_msg("SYN[~s] Received DISCOVER request from node '~s'for ~s and scope '~s'",
-        [node(), RemoteScopeNode, Handler, Scope]
+    error_logger:info_msg("SYN[~s|~s] Received DISCOVER request from node '~s'",
+        [Handler, Scope, RemoteScopeNode]
     ),
     %% send local data to remote
     {ok, LocalData} = Handler:get_local_data(State),
@@ -229,8 +229,8 @@ handle_info({'3.0', ack_sync, RemoteScopePid, Data}, #state{
     scope = Scope
 } = State) ->
     RemoteScopeNode = node(RemoteScopePid),
-    error_logger:info_msg("SYN[~s] Received ACK SYNC (~w entries) from node '~s' for ~s and scope '~s'",
-        [node(), length(Data), RemoteScopeNode, Handler, Scope]
+    error_logger:info_msg("SYN[~s|~s] Received ACK SYNC (~w entries) from node '~s'",
+        [Handler, Scope, length(Data), RemoteScopeNode]
     ),
     %% save remote data
     Handler:save_remote_data(Data, State),
@@ -259,8 +259,8 @@ handle_info({'DOWN', MRef, process, Pid, Reason}, #state{
     RemoteNode = node(Pid),
     case maps:take(RemoteNode, NodesMap) of
         {Pid, NodesMap1} ->
-            error_logger:info_msg("SYN[~s] Scope Process '~s' for ~s is DOWN on node '~s': ~p",
-                [node(), Scope, Handler, RemoteNode, Reason]
+            error_logger:info_msg("SYN[~s|~s] Scope Process is DOWN on node '~s': ~p",
+                [Handler, Scope, RemoteNode, Reason]
             ),
             Handler:purge_local_data_for_node(RemoteNode, State),
             {noreply, State#state{nodes_map = NodesMap1}};
@@ -278,8 +278,8 @@ handle_info({nodeup, RemoteNode}, #state{
     handler = Handler,
     scope = Scope
 } = State) ->
-    error_logger:info_msg("SYN[~s] Node '~s' has joined the cluster, sending discover message for ~s and scope '~s'",
-        [node(), RemoteNode, Handler, Scope]
+    error_logger:info_msg("SYN[~s|~s] Node '~s' has joined the cluster, sending discover message",
+        [Handler, Scope, RemoteNode]
     ),
     send_to_node(RemoteNode, {'3.0', discover, self()}, State),
     {noreply, State};
@@ -298,7 +298,7 @@ handle_continue(after_init, #state{
     handler = Handler,
     scope = Scope
 } = State) ->
-    error_logger:info_msg("SYN[~s] Discovering the cluster for ~s and scope '~s'", [node(), Handler, Scope]),
+    error_logger:info_msg("SYN[~s|~s] Discovering the cluster", [Handler, Scope]),
     broadcast_all_cluster({'3.0', discover, self()}, State),
     {noreply, State}.
 
@@ -306,8 +306,8 @@ handle_continue(after_init, #state{
 %% Terminate
 %% ----------------------------------------------------------------------------------------------------------
 -spec terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()), #state{}) -> any().
-terminate(Reason, #state{handler = Handler}) ->
-    error_logger:info_msg("SYN[~s] ~s terminating with reason: ~p", [node(), Handler, Reason]).
+terminate(Reason, #state{handler = Handler, scope = Scope}) ->
+    error_logger:info_msg("SYN[~s|~s] ~s terminating with reason: ~p", [Handler, Scope, Handler, Reason]).
 
 %% ----------------------------------------------------------------------------------------------------------
 %% Convert process state when code is changed.

+ 6 - 6
src/syn_groups.erl

@@ -303,8 +303,8 @@ handle_call({leave_on_owner, RequesterNode, GroupName, Pid}, _From, #state{
             {reply, {ok, {Meta, TableByPid}}, State}
     end;
 
-handle_call(Request, From, State) ->
-    error_logger:warning_msg("SYN[~s] Received from ~p an unknown call message: ~p", [node(), From, Request]),
+handle_call(Request, From, #state{scope = Scope} = State) ->
+    error_logger:warning_msg("SYN[~s|~s] Received from ~p an unknown call message: ~p", [?MODULE, Scope, From, Request]),
     {reply, undefined, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -338,8 +338,8 @@ handle_info({'DOWN', _MRef, process, Pid, Reason}, #state{
     case find_groups_entries_by_pid(Pid, TableByPid) of
         [] ->
             error_logger:warning_msg(
-                "SYN[~s] Received a DOWN message from an unknown process ~p with reason: ~p",
-                [node(), Pid, Reason]
+                "SYN[~s|~s] Received a DOWN message from an unknown process ~p with reason: ~p",
+                [?MODULE, Scope, Pid, Reason]
             );
 
         Entries ->
@@ -355,8 +355,8 @@ handle_info({'DOWN', _MRef, process, Pid, Reason}, #state{
     %% return
     {noreply, State};
 
-handle_info(Info, State) ->
-    error_logger:warning_msg("SYN[~s] Received an unknown info message: ~p", [node(), Info]),
+handle_info(Info, #state{scope = Scope} = State) ->
+    error_logger:warning_msg("SYN[~s|~s] Received an unknown info message: ~p", [?MODULE, Scope, Info]),
     {noreply, State}.
 
 %% ----------------------------------------------------------------------------------------------------------

+ 12 - 12
src/syn_registry.erl

@@ -261,8 +261,8 @@ handle_call({unregister_on_owner, RequesterNode, Name, Pid}, _From, #state{
             {reply, {{error, undefined}, undefined}, State}
     end;
 
-handle_call(Request, From, State) ->
-    error_logger:warning_msg("SYN[~s] Received from ~p an unknown call message: ~p", [node(), From, Request]),
+handle_call(Request, From, #state{scope = Scope} = State) ->
+    error_logger:warning_msg("SYN[~s|~s] Received from ~p an unknown call message: ~p", [?MODULE, Scope, From, Request]),
     {reply, undefined, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -295,8 +295,8 @@ handle_info({'DOWN', _MRef, process, Pid, Reason}, #state{
     case find_registry_entries_by_pid(Pid, TableByPid) of
         [] ->
             error_logger:warning_msg(
-                "SYN[~s] Received a DOWN message from an unknown process ~p with reason: ~p",
-                [node(), Pid, Reason]
+                "SYN[~s|~s] Received a DOWN message from an unknown process ~p with reason: ~p",
+                [?MODULE, Scope, Pid, Reason]
             );
 
         Entries ->
@@ -312,8 +312,8 @@ handle_info({'DOWN', _MRef, process, Pid, Reason}, #state{
     %% return
     {noreply, State};
 
-handle_info(Info, State) ->
-    error_logger:warning_msg("SYN[~s] Received an unknown info message: ~p", [node(), Info]),
+handle_info(Info, #state{scope = Scope} = State) ->
+    error_logger:warning_msg("SYN[~s|~s] Received an unknown info message: ~p", [?MODULE, Scope, Info]),
     {noreply, State}.
 
 %% ----------------------------------------------------------------------------------------------------------
@@ -551,8 +551,8 @@ resolve_conflict(Scope, Name, {Pid, Meta, Time}, {TablePid, TableMeta, TableTime
     case PidToKeep of
         Pid ->
             %% -> we keep the remote pid
-            error_logger:info_msg("SYN[~s] Registry CONFLICT for name ~p@~s: ~p vs ~p -> keeping remote: ~p",
-                [node(), Name, Scope, Pid, TablePid, Pid]
+            error_logger:info_msg("SYN[~s|~s] Registry CONFLICT for name ~p: ~p vs ~p -> keeping remote: ~p",
+                [?MODULE, Scope, Name, Pid, TablePid, Pid]
             ),
             %% update locally, the incoming sync_register will update with the time coming from remote node
             update_local_table(Name, TablePid, {Pid, Meta, Time, undefined}, TableByName, TableByPid),
@@ -564,8 +564,8 @@ resolve_conflict(Scope, Name, {Pid, Meta, Time}, {TablePid, TableMeta, TableTime
 
         TablePid ->
             %% -> we keep the local pid
-            error_logger:info_msg("SYN[~s] Registry CONFLICT for name ~p@~s: ~p vs ~p -> keeping local: ~p",
-                [node(), Name, Scope, Pid, TablePid, TablePid]
+            error_logger:info_msg("SYN[~s|~s] Registry CONFLICT for name ~p: ~p vs ~p -> keeping local: ~p",
+                [?MODULE, Scope, Name, Pid, TablePid, TablePid]
             ),
             %% overwrite with updated time
             ResolveTime = erlang:system_time(),
@@ -574,8 +574,8 @@ resolve_conflict(Scope, Name, {Pid, Meta, Time}, {TablePid, TableMeta, TableTime
             syn_gen_scope:broadcast({'3.0', sync_register, Name, TablePid, TableMeta, ResolveTime}, State);
 
         Invalid ->
-            error_logger:info_msg("SYN[~s] Registry CONFLICT for name ~p@~s: ~p vs ~p -> none chosen (got: ~p)",
-                [node(), Name, Scope, Pid, TablePid, Invalid]
+            error_logger:info_msg("SYN[~s|~s] Registry CONFLICT for name ~p: ~p vs ~p -> none chosen (got: ~p)",
+                [?MODULE, Scope, Name, Pid, TablePid, Invalid]
             ),
             %% remove
             maybe_demonitor(TablePid, TableByPid),

+ 1 - 1
src/syn_sup.erl

@@ -50,7 +50,7 @@ get_node_scopes() ->
 
 -spec add_node_to_scope(Scope :: atom()) -> ok.
 add_node_to_scope(Scope) ->
-    error_logger:info_msg("SYN[~s] Adding node to scope '~s'", [node(), Scope]),
+    error_logger:info_msg("SYN[~s] Adding node to scope", [Scope]),
     %% save to ENV (failsafe if sup is restarted)
     CustomScopes0 = case application:get_env(syn, custom_scopes) of
         undefined -> #{};