Support Modules
Logging#
- class logic1.support.logging.DeltaTimeFormatter[source]#
Bases:
Formatter
Allows to log the time relative to a reference time by adding an attribute delta to the
logging.LogRecord
.>>> import logging, sys, time >>> logger = logging.getLogger('demo') >>> stream_handler = logging.StreamHandler(stream=sys.stdout) >>> delta_time_formatter = DeltaTimeFormatter('%(delta)s: %(message)s') >>> stream_handler.setFormatter(delta_time_formatter) >>> logger.addHandler(stream_handler) >>> delta_time_formatter.set_reference_time(time.time()) >>> time.sleep(0.01) >>> logger.warning('Hello world!') 0:00:00.012: Hello world!
- get_reference_time() float [source]#
Get the reference time in seconds since the epoch. This is compatible with the output of
time.time()
.
- class logic1.support.logging.RateFilter[source]#
Bases:
Filter
Allows to specify a log rate, which specifies the minimal time in seconds that has to pass between two logs. The initial value of the rate ist 0.0. The filter is initially on.
>>> import logging, sys >>> logger = logging.getLogger('demo') >>> stream_handler = logging.StreamHandler(stream=sys.stdout) >>> logger.addHandler(stream_handler) >>> rate_filter = RateFilter() >>> rate_filter.set_rate(0.001) >>> logger.addFilter(rate_filter) >>> for count in range(1000): ... logger.warning(f'{count=}') count=0 count=276 count=571 count=868
- class logic1.support.logging.Timer[source]#
Bases:
object
A simple timer measuring the wall time in seconds relative to the last
reset()
. Instances of the Timer are implicitly reset when they are created.>>> import time >>> timer = Timer() >>> timer.get() 1.7881393432617188e-05 >>> time.sleep(0.1) >>> timer.get() 0.10515975952148438