orangeqs.juice.service._logging#
Handlers and Utilities for Service Logging.
Module Contents#
Classes#
Queue listener that stops with a time limit. |
|
Queue handler that passes records to |
|
JuiceInfluxLoggingHandler instances dispatch logging events to influx. |
Functions#
Return a queue handler that writes the service logs to InfluxDB. |
Data#
API#
- orangeqs.juice.service._logging.QUEUE_SIZE#
1000
- orangeqs.juice.service._logging.STOP_TIMEOUT_S#
3
- class orangeqs.juice.service._logging.JuiceQueueListener(log_queue: queue.Queue[logging.LogRecord], *handlers: logging.Handler)#
Bases:
logging.handlers.QueueListenerQueue listener that stops with a time limit.
Podman kills a service 10 s after asking it to stop, so on stop the listener gets
STOP_TIMEOUT_Sto flush the queue. The records still waiting after that are dropped and their number is reported on stderr.- start() None#
Start the listener.
This starts up a background thread to monitor the queue for LogRecords to process.
- class orangeqs.juice.service._logging.JuiceQueueHandler(target: logging.Handler)#
Bases:
logging.handlers.QueueHandlerQueue handler that passes records to
targetin a background thread.Logging never waits for
target, so a slow handler (such as the InfluxDB one) does not block the event loop. The queue is bounded: when it is full, new records are dropped and one warning is printed to stderr. The number of dropped records is printed by the first log call after the queue drained to half, or byclose().- filter(record: logging.LogRecord) bool#
Determine if a record is loggable by consulting all the filters.
The default is to allow the record to be logged; any filter can veto this by returning a false value. If a filter attached to a handler returns a log record instance, then that instance is used in place of the original log record in any further processing of the event by that handler. If a filter returns any other true value, the original log record is used in any further processing of the event by that handler.
If none of the filters return false values, this method returns a log record. If any of the filters return a false value, this method returns a false value.
.. versionchanged:: 3.2
Allow filters to be just callables.
.. versionchanged:: 3.12 Allow filters to return a LogRecord instead of modifying it in place.
- enqueue(record: logging.LogRecord) None#
Enqueue a record.
The base implementation uses put_nowait. You may want to override this method if you want to use blocking, timeouts or custom queue implementations.
- prepare(record: logging.LogRecord) logging.LogRecord#
Prepare a record for queuing. The object returned by this method is enqueued.
The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place. Specifically, it overwrites the record’s
msgandmessageattributes with the merged message (obtained by calling the handler’sformatmethod), and sets theargs,exc_infoandexc_textattributes to None.You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact.
- orangeqs.juice.service._logging.influx_queue_handler(*, bucket: str, service: str) orangeqs.juice.service._logging.JuiceQueueHandler#
Return a queue handler that writes the service logs to InfluxDB.
- class orangeqs.juice.service._logging.JuiceInfluxLoggingHandler(*, bucket: str, service: str)#
Bases:
logging.HandlerJuiceInfluxLoggingHandler instances dispatch logging events to influx.
There is no need to set a Formatter. The raw input will be passed on to the influx write api.
- DEFAULT_LOG_RECORD_KEYS#
None
- emit(record: logging.LogRecord) None#
Emit a record via the influxDB WriteApi.