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
- 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
- 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