maestral.logging

This module defines custom logging records and handlers.

Module Contents

maestral.logging.safe_journal_sender(MESSAGE: str, **kwargs)None[source]
class maestral.logging.EncodingSafeLogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None, **kwargs)[source]

Bases: logging.LogRecord

A log record which ensures that messages contain only unicode characters

This is useful when log messages may contain file paths generates by OS APIs. In Python, such path strings may contain surrogate escapes and will therefore raise a UnicodeEncodeError under many circumstances (printing to stdout, etc).

getMessage(self)str[source]

Formats the log message and replaces all surrogate escapes with “�”.

class maestral.logging.CachedHandler(level: int = logging.NOTSET, maxlen: Optional[int] = 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
  • level – Initial log level. Defaults to NOTSET.

  • maxlen – Maximum number of records to store. If None, all records will be stored. Defaults to None.

cached_records :Deque[logging.LogRecord][source]
emit(self, record: logging.LogRecord)None[source]

Logs the specified log record and saves it to the cache.

Parameters

record – Log record.

wait_for_emit(self, timeout: Optional[float])bool[source]

Blocks until a new record is emitted.

Parameters

timeout – Maximum time to block before returning.

Returns

True if there was a status change, False in case of a timeout.

getLastMessage(self)str[source]
Returns

The log message of the last record or an empty string.

getAllMessages(self) → List[str][source]
Returns

A list of all record messages.

clear(self)None[source]

Clears all cached records.

class maestral.logging.SdNotificationHandler(level=NOTSET)[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.

notifier[source]
emit(self, record: logging.LogRecord)None[source]

Sends the record massage to systemd as service status.

Parameters

record – Log record.