Logging Facilities

Netcat objects can be instrumented by providing a Logger object to its constructor. The job of a Logger is to receive events provided by the Netcat (for example, “we are sending data” or “we got an EOF”) and do something with them.

class nclib.logger.Logger[source]

The base class for loggers for use with Netcat objects. Each of these methods will be called to indicate a given event.

buffering(data)[source]

Called to indicate that some data has been received and inserted into the buffer

connected(peer)[source]

Called with a tuple of the peer to indicate “connection established”, either as a client or a server

eofed()[source]

Called to indicate that reading from the socket resulted in an EOF condition

interact_ending()[source]

Called to indicate that an interactive session is ending

interact_starting()[source]

Called to indicate that an interactive session is beginning

interrupted()[source]

Called to indicate that a socket operation was interrupted via ctrl-c

requesting_recv(n, timeout)[source]

Called to indicate that the user has asked for a receive of at most n bytes

requesting_recv_all(timeout)[source]

Called to indicate that the user has asked to receive all data until close

requesting_recv_exactly(n, timeout)[source]

Called to indicate that the user has asked to receive exactly n bytes

requesting_recv_until(s, max_size, timeout)[source]

Called to indicate that the user has asked to receive until a given string appears

requesting_send(data)[source]

Called to indicate that the user has asked to send all of some data

sending(data)[source]

Called to indicate that some data has been sent over the wire

unbuffering(data)[source]

Called to indicate that some data is being extracted from the buffer and returned to the user

class nclib.logger.StandardLogger(log, log_yield=False, show_headers=True, hex_dump=False, split_newlines=True, send_prefix='>> ', recv_prefix='<< ', no_eol_indicator='\x1b[3m%\x1b[0m')[source]

A logger which produces a human-readable log of what’s happening

Parameters:
  • log – A simplesock object to which the logs should be sent

  • log_yield – Whether to log receives when they are recieved and written to the buffer or when they are unbuffered and returned to the user

  • show_headers – Whether to show metadata notices about user actions and exceptional conditions

  • hex_dump – Whether to encode logged data as a canonical hexdump

  • split_newlines – When in non-hex mode, whether logging should treat newlines as record separators

class nclib.logger.TeeLogger(log_send=None, log_recv=None, log_yield=False)[source]

A logger which feeds a copy of the input and output streams to a given stream

Parameters:
  • log_send – A simplesock object to log all sends to, or None

  • log_recv – A simplesock object to log all recvs to, or None

  • log_yield – Whether recv logging should happen when data is buffered or returned to the user

class nclib.logger.ManyLogger(children)[source]

A logger which dispatches all events to all its children, which are other loggers. You shouldn’t have to deal with this much; it’s used automatically by the Netcat.

Parameters:

children – A list of loggers to which to dispatch events