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 viastr()
.
-
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¶
-
-
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 encodeddict
produced byStructLog
. Thedict
is encoded to a string usingencode_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 thecomponent
as bound variable.- Parameters
component (
str
) – the value of thecomponent
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, onlyCRITICAL
errors are shown to console; otherwiseINFO
and above.ready (
multiprocessing.Event
) – an event that is set once the logging server is ready.