teos.logger

class JsonMsgLogger(name, level=0)[source]

Bases: logging.Logger

Works exactly like logging.Logger but represents dict messages as json. Useful to prevent dicts being cast to strings via str().

makeRecord(*args, **kwargs)[source]

Makes a record where the message is json encoded.

class LogRecordSocketReceiver(host='localhost', port=9020, handler=<class 'teos.logger.LogRecordStreamHandler'>)[source]

Bases: socketserver.ThreadingTCPServer

Simple TCP socket-based logging receiver.

allow_reuse_address = True
serve_forever(poll_interval=0.5)[source]

Serves the logger server until the tower is stopped.

class LogRecordStreamHandler(request, client_address, server)[source]

Bases: socketserver.StreamRequestHandler

Handler for a streaming logging request. Sends to the logger any received log message, after some preprocessing.

handle()[source]

Handle multiple requests - each expected to be a 4-byte length, followed by the LogRecord in pickle format. Logs the record according to whatever policy is configured locally.

static handle_log_record(record)[source]

Processes log records received via the socket. The record’s msg field is expected to be an encoded dict produced by StructLog. The dict is encoded to a string using encode_event_dict and sent to the logger with the name specified in the record.

Parameters

record (logging.LogRecord) – a log record.

encode_event_dict(event_dict)[source]

Encodes an event dictionary in a nicely formatted string, following the general format:

timestamp [component] event (attr1=value1, attr2=value2, ...)

Where values that are not present are omitted. See unit tests for a more precise specification.

get_logger(component=None)[source]

Returns a Logger, that has the given component in all future log entries.

Returns

A proxy obtained from structlog.get_logger with the component as bound variable.

Parameters

component (str) – the value of the component field that will be attached to all the logs issued by this logger.

ignore_signal(_, __)[source]

Ignores stop signals so the teardown can be handled by the main process.

serve(log_file_path, silent, ready)[source]

Sets up logging on console and file, and serves the tcp logging server on localhost:TCP_LOGGING_PORT. This method is meant to be run in a separate process and provides the logging service.

Parameters
  • log_file_path (str) – the full path and log file name.

  • silent (bool) – if True, only CRITICAL errors are shown to console; otherwise INFO and above.

  • ready (multiprocessing.Event) – an event that is set once the logging server is ready.

setup_logging()[source]

Configures the logging options. It must be called only once, before using get_logger.

Raises

RuntimeError – if setup_logging had already been called.