Add logging of IP address and process number

At the beginning of each client connection, log the IP address along
with Erlang's process number associated with the socket.

This allows us to pinpoint clients who encounter problems and help
them out.
This commit is contained in:
Maciej Szlosarczyk 2019-07-30 10:46:11 +03:00
parent 65d5e6ccc9
commit 9902b5ac72
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765

View file

@ -40,6 +40,7 @@ handle_cast(serve,
State = #state{socket = Socket,
session_id = _SessionId}) ->
{ok, {PeerIp, _PeerPort}} = ssl:peername(Socket),
log_opened_connection(PeerIp),
case ssl:handshake(Socket) of
{ok, SecureSocket} ->
NewState = state_from_socket(SecureSocket, State),
@ -168,6 +169,11 @@ log_on_invalid_handshake(Ip, Error) ->
[ReadableIp, Error]),
exit(normal).
log_opened_connection(Ip) ->
ReadableIp = epp_util:readable_ip(Ip),
lager:info("New client connection. IP: ~s, Process: ~p.~n",
[ReadableIp, self()]).
%% Extract state info from socket. Fail if you must.
state_from_socket(Socket, State) ->
{ok, PeerCert} = ssl:peercert(Socket),