maestral.logging
This module defines custom logging records and handlers.
- class maestral.logging.CachedHandler(level=0, maxlen=None)[source]
Bases:
logging.Handler
Handler which stores past records
This is used to populate Maestral’s status and error interfaces. The method
wait_for_emit()
can be used from another thread to block until a new record is emitted, for instance to react to state changes.- Parameters
- Return type
None
- cached_records: Deque[logging.LogRecord]
- emit(record)[source]
Logs the specified log record and saves it to the cache.
- Parameters
record (logging.LogRecord) – Log record.
- Return type
None
- class maestral.logging.SdNotificationHandler(level=0)[source]
Bases:
logging.Handler
Handler which emits messages as systemd notifications
This is useful when used from a systemd service and will do nothing when no NOTIFY_SOCKET is provided.
Initializes the instance - basically setting the formatter to None and the filter list to empty.
- notifier = <sdnotify.SystemdNotifier object>
- emit(record)[source]
Sends the record massage to systemd as service status.
- Parameters
record (logging.LogRecord) – Log record.
- Return type
None
- maestral.logging.setup_logging(config_name, log_to_stderr=True)[source]
Sets up logging handlers for the given config name. The following handlers are installed for the root logger:
RotatingFileHandler: Writes logs to the appropriate log file for the config. Log level is determined by the config value.
StreamHandler: Writes logs to stderr. Log level is determined by the config value. This will be replaced by a null handler if
log_to_stderr
isFalse
.SdNotificationHandler: Sends all log messages of level INFO and higher to the NOTIFY_SOCKET if provided as an environment variable. The log level is fixed.
JournalHandler: Writes logs to the systemd journal. Log level is determined by the config value. Will be replaced by a null handler if not started as a systemd service or if python-systemd is not installed.
Any previous loggers are cleared.
- Parameters
- Returns
(log_handler_file, log_handler_stream, log_handler_sd, log_handler_journal)
- Return type
Tuple[logging.handlers.RotatingFileHandler, Union[logging.StreamHandler, logging.NullHandler], maestral.logging.SdNotificationHandler, Union[journal.JournalHandler, logging.NullHandler]]