teos.logger¶
-
class
JsonMsgLogger(name, level=0)[source]¶ Bases:
logging.LoggerWorks exactly like
logging.Loggerbut represents dict messages as json. Useful to prevent dicts being cast to strings viastr().
-
class
LogRecordSocketReceiver(host='localhost', port=9020, handler=<class 'teos.logger.LogRecordStreamHandler'>)[source]¶ Bases:
socketserver.ThreadingTCPServerSimple TCP socket-based logging receiver.
-
allow_reuse_address= True¶
-
-
class
LogRecordStreamHandler(request, client_address, server)[source]¶ Bases:
socketserver.StreamRequestHandlerHandler 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
LogRecordin 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
msgfield is expected to be an encodeddictproduced byStructLog. Thedictis encoded to a string usingencode_event_dictand 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_loggerwith thecomponentas bound variable.- Parameters
component (
str) – the value of thecomponentfield 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, onlyCRITICALerrors are shown to console; otherwiseINFOand above.ready (
multiprocessing.Event) – an event that is set once the logging server is ready.