slimta.logging.socket

Utilities to make logging consistent and easy for any socket interaction.

slimta.logging.socket.socket_error_log_level = 40

The log level for logging socket.error exceptions. The default log level is logging.ERROR.

class slimta.logging.socket.SocketLogger(logger)

Bases: object

Provides a limited set of log methods that slimta packages may use. This prevents free-form logs from mixing in with standard, machine- parseable logs.

Parameters:loglogging.Logger object to log through.
send(socket, data)

Logs a socket send() operation along with the peer the socket is connected to.

Parameters:
  • socket – The socket that has sent data.
  • data – The data that was sent.
recv(socket, data)

Logs a socket recv() operation along with the peer the socket is connected to.

Parameters:
  • socket – The socket that has received data.
  • data – The data that was received.
accept(server, client[, address=None])

Logs a socket accept() operation along with the server that received it and the peer that initiated it.

Parameters:
  • server – The server socket that received the connection.
  • client – The client socket that was accepted.
  • address – If known, the peer address of the client socket.
connect(socket[, address=None])

Logs a socket connect() operation along with the peer the socket is connected to. Logged at the DEBUG level.

Parameters:
  • socket – The socket that was connected.
  • address – If known, the peer address the socket connected to.
encrypt(socket, context)

Logs a socket encryption operation along with the certificate and key files used and whether the socket is acting as the client or the server.

Parameters:
  • socket – The socket that was shutdown.
  • context (SSLContext) – The SSL context that was used.
shutdown(socket, how)

Logs a socket shutdown() operation along with which part of the socket was shut down. Logged at the DEBUG level.

Parameters:
  • socket – The socket that was shutdown.
  • how – The how parameter, as passed to shutdown().
close(socket)

Logs a socket close() operation along with the peer the socket was connected to. Logged at the DEBUG level.

Parameters:socket – The socket that was closed.
error(socket, exc[, address=None])

Logs a socket.error exception. Logged at the ERROR level and does not include a stack trace.

Parameters:
  • socket – The socket that threw the error, if available.
  • exc – The exception that was thrown.
  • address – The remote address that threw the error, if available.
proxyproto_success(socket, src_addr)

Logs a successful proxy protocol header, with the new source address information. Logged at the DEBUG level.

Parameters:
  • socket – The socket that received the header.
  • src_addr – The new source address information.
proxyproto_invalid(socket, exc)

Logs an invalid proxy protocol header, with an exception provided by the ProxyProtocol class. Logged at the WARNING level.

Parameters:
  • socket – The socket that failed the proxy protocol.
  • exc – The exception generated during the failure.
proxyproto_local(sock)

Logs a successful proxy protocol header that indicates a “local” connection from the proxy itself, to perform a health check.