@@ -165,10 +165,13 @@ waiting_ip(enter, _OldState, _Data) ->
165165waiting_ip (state_timeout , check_ip , Data ) ->
166166 case grisp_connect_utils :check_inet_ipv4 () of
167167 {ok , IP } ->
168- ? LOG_INFO (#{event => checked_ip , ip => IP }),
168+ ? LOG_DEBUG (#{description => ? FORMAT (" IP Address available: ~s " ,
169+ [format_ipv4 (IP )]),
170+ event => checked_ip , ip => format_ipv4 (IP )}),
169171 {next_state , connecting , Data };
170172 invalid ->
171- ? LOG_DEBUG (#{event => waiting_ip }),
173+ ? LOG_DEBUG (#{description => <<" Waiting for an IP address do connect to grisp.io" >>,
174+ event => waiting_ip }),
172175 {keep_state_and_data , [{state_timeout , 1000 , check_ip }]}
173176 end ;
174177? HANDLE_COMMON .
@@ -179,14 +182,14 @@ connecting(enter, _OldState, #data{retry_count = RetryCount}) ->
179182 ? LOG_DEBUG (" Scheduling connection attempt in ~w ms" , [Delay ]),
180183 {keep_state_and_data , [{state_timeout , Delay , connect }]};
181184connecting (state_timeout , connect , Data = # data {conn = undefined }) ->
182- ? LOG_INFO (#{description => <<" Connecting to grisp.io" >>,
185+ ? LOG_INFO (#{description => <<" Connecting to grisp.io ... " >>,
183186 event => connecting }),
184187 case conn_start (Data ) of
185188 {ok , Data2 } ->
186189 {keep_state , Data2 , [{state_timeout , ? CONNECT_TIMEOUT , timeout }]};
187190 {error , Reason } ->
188- ? LOG_WARNING (" Failed to connect to grisp.io: ~p " , [Reason ],
189- #{ event => connection_failed , reason => Reason }),
191+ ? LOG_WARNING (#{ description => ? FORMAT ( " Failed to connect to grisp.io: ~p " , [Reason ]) ,
192+ event => connection_failed , reason => Reason }),
190193 reconnect (Data , Reason )
191194 end ;
192195connecting (state_timeout , timeout , Data ) ->
@@ -237,11 +240,13 @@ handle_common(info, reboot, _, _) ->
237240 init :stop (),
238241 keep_state_and_data ;
239242handle_common (info , {'EXIT' , Conn , Reason }, _State , Data = # data {conn = Conn }) ->
240- % The connection process died
241- ? LOG_WARNING (#{description =>
242- ? FORMAT (" The connection to grisp.io died: ~p " , [Reason ]),
243- event => connection_failed , reason => Reason }),
244- reconnect (conn_died (Data ), Reason );
243+ RealReason = case Reason of
244+ {shutdown , R } -> R ;
245+ R -> R
246+ end ,
247+ ? LOG_WARNING (#{description => ? FORMAT (" Connection to grisp.io terminated: ~p " , [RealReason ]),
248+ event => connection_failed , reason => RealReason }),
249+ reconnect (conn_died (Data ), RealReason );
245250handle_common (info , {'EXIT' , _Conn , _Reason }, _State , _Data ) ->
246251 % Ignore any EXIT from past jarl connections
247252 keep_state_and_data ;
@@ -253,11 +258,9 @@ handle_common(cast, Cast, _, _) ->
253258 error ({unexpected_cast , Cast });
254259handle_common ({call , _ }, Call , _ , _ ) ->
255260 error ({unexpected_call , Call });
256- handle_common (info , Info , State , Data ) ->
257- ? LOG_ERROR (#{event => unexpected_info ,
258- info => Info ,
259- state => State ,
260- data => Data }),
261+ handle_common (info , Info , State , _Data ) ->
262+ ? LOG_WARNING (#{description => <<" Unexpected message" >>,
263+ event => unexpected_info , info => Info , state => State }),
261264 keep_state_and_data .
262265
263266
@@ -278,6 +281,9 @@ as_bin(Binary) when is_binary(Binary) -> Binary;
278281as_bin (List ) when is_list (List ) -> list_to_binary (List );
279282as_bin (Atom ) when is_atom (Atom ) -> atom_to_binary (Atom ).
280283
284+ format_ipv4 ({A , B , C , D }) ->
285+ ? FORMAT (" ~w .~w .~w .~w " , [A , B , C , D ]).
286+
281287handle_connection_message (_Data , {response , _Result , #{on_result := undefined }}) ->
282288 keep_state_and_data ;
283289handle_connection_message (Data , {response , Result , #{on_result := OnResult }}) ->
0 commit comments