patroni.log module¶
Patroni logging facilities.
Daemon processes will use a 2-step logging handler. Whenever a log message is issued it is initially enqueued in-memory and is later asynchronously flushed by a thread to the final destination.
-
class
patroni.log.PatroniLogger¶ Bases:
threading.ThreadLogging thread for the Patroni daemon process.
It is a 2-step logging approach. Any time a log message is issued it is initially enqueued in-memory, and then asynchronously flushed to the final destination by the logging thread.
See also
QueueHandler: object used for enqueueing messages in-memory.Variables: - DEFAULT_LEVEL – default logging level (
INFO). - DEFAULT_TRACEBACK_LEVEL – default traceback logging level (
ERROR). - DEFAULT_FORMAT – default format of log messages (
%(asctime)s %(levelname)s: %(message)s). - NORMAL_LOG_QUEUE_SIZE – expected number of log messages per HA loop when operating under a normal situation.
- DEFAULT_MAX_QUEUE_SIZE – default maximum queue size for holding a backlog of log messages that are pending to be flushed.
- LOGGING_BROKEN_EXIT_CODE – exit code to be used if it detects(
5). - log_handler – log handler that is currently being used by the thread.
- log_handler_lock – lock used to modify
log_handler.
-
DEFAULT_FORMAT= '%(asctime)s %(levelname)s: %(message)s'¶
-
DEFAULT_LEVEL= 'INFO'¶
-
DEFAULT_MAX_QUEUE_SIZE= 1000¶
-
DEFAULT_TRACEBACK_LEVEL= 'ERROR'¶
-
LOGGING_BROKEN_EXIT_CODE= 5¶
-
NORMAL_LOG_QUEUE_SIZE= 2¶
-
queue_size¶ Number of log records in the queue.
-
records_lost¶ Number of logging records that have been lost while the queue was full.
-
reload_config(config: Dict[str, Any]) → None¶ Apply log related configuration.
Note
It is also able to deal with runtime configuration changes.
Parameters: config – logsection from Patroni configuration.
-
run() → None¶ Run logger’s thread main loop.
Keep consuming log queue until requested to quit through
Nonespecial log record.
-
shutdown() → None¶ Shut down the logger thread.
-
update_loggers() → None¶ Configure loggers’ log level as defined in
log.loggerssection of Patroni configuration.Note
It creates logger objects that are not defined yet in the log manager.
- DEFAULT_LEVEL – default logging level (
-
class
patroni.log.ProxyHandler(patroni_logger: patroni.log.PatroniLogger)¶ Bases:
logging.HandlerHandle log records in place of pending log handlers.
Note
This is used to handle log messages while the logger thread has not started yet, in which case the queue-based handler is not yet started.
Variables: patroni_logger – the logger thread. -
emit(record: logging.LogRecord) → None¶ Emit each log record that is handled.
Will push the log record down to
handle()method of the currently configured log handler.Parameters: record – the record that was emitted.
-
-
class
patroni.log.QueueHandler¶ Bases:
logging.HandlerQueue-based logging handler.
Variables: queue – queue to hold log messages that are pending to be flushed to the final destination. -
emit(record: logging.LogRecord) → None¶ Handle each log record that is emitted.
Call
_put_record()to enqueue the emitted log record.Also check if we have previously lost any log record, and if so, log a
WARNINGmessage.Parameters: record – the record that was emitted.
-
records_lost¶ Number of log messages that have been lost while the queue was full.
-
-
patroni.log.debug_exception(self: logging.Logger, msg: object, *args, **kwargs) → None¶ Add full stack trace info to debug log messages and partial to others.
Handle
exception()calls for self.Note
- If self log level is set to
DEBUG, then issue aDEBUGmessage with the complete stack trace; - If self log level is
INFOor higher, then issue anERRORmessage with only the last line of - the stack trace.
- If self log level is
Parameters: - self – logger for which
exception()will be processed. - msg – the message related to the exception to be logged.
- args – positional arguments to be passed to
debug()orerror(). - kwargs – keyword arguments to be passed to
debug()orerror().
- If self log level is set to
-
patroni.log.error_exception(self: logging.Logger, msg: object, *args, **kwargs) → None¶ Add full stack trace info to error messages.
Handle
exception()calls for self.Note
- By default issue an
ERRORmessage with the complete stack trace. If you do not want to show the complete stack trace, call withexc_info=False.
Parameters: - self – logger for which
exception()will be processed. - msg – the message related to the exception to be logged.
- args – positional arguments to be passed to
error(). - kwargs – keyword arguments to be passed to
error().
- By default issue an