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.Thread
Logging 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¶
- reload_config(config: Dict[str, Any]) None ¶
Apply log related configuration.
Note
It is also able to deal with runtime configuration changes.
- Parameters
config –
log
section from Patroni configuration.
- class patroni.log.ProxyHandler(patroni_logger: patroni.log.PatroniLogger)¶
Bases:
logging.Handler
Handle 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.Handler
Queue-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
WARNING
message.- Parameters
record – the record that was emitted.
- patroni.log.debug_exception(self: logging.Logger, msg: object, *args: Any, **kwargs: Any) 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 aDEBUG
message with the complete stack trace;- If self log level is
INFO
or higher, then issue anERROR
message 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()
.
- patroni.log.error_exception(self: logging.Logger, msg: object, *args: Any, **kwargs: Any) None ¶
Add full stack trace info to error messages.
Handle
exception()
calls for self.Note
By default issue an
ERROR
message 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()
.