libmuscle.manager.logger module

class libmuscle.manager.logger.Formatter(fmt=None, datefmt=None, style='%', validate=True)[source]

Bases: Formatter

A custom formatter that can format remote messages.

formatMessage(record: LogRecord) str[source]

Formats a message for a record.

If the record contains a time_stamp attribute, assumes that it is a remote record and formats accordingly, otherwise formats as a local record.

Parameters:

record – The LogRecord to format.

Returns:

The formatted message.

usesTime() bool[source]

Tells the formatter to make asctime available.

class libmuscle.manager.logger.Logger(log_dir: Path | None = None, log_level: str | None = None)[source]

Bases: object

The MUSCLE3 Manager Logger component.

The Logger component configures the local logging system to output to the central log file, and it accepts messages from remote instances to write to it as well. Log levels are also set here.

close() None[source]
log_message(instance_id: str, timestamp: Timestamp, level: LogLevel, text: str) None[source]

Log a message.

Parameters:
  • instance_id – Identifier of the instance that generated the message.

  • timestamp – Time when this log message was generated, according to the clock on that machine.

  • level – The log level of the message.

  • text – The message text.

libmuscle.manager.logger.last_lines(file: Path, count: int) str[source]

Utility function that returns the last lines of a text file.

This opens the file and returns the final count lines. It reads at most 10000 bytes, to avoid memory problems if the file contains e.g. a large amount of binary data.

Parameters:
  • file – The file to read

  • count – Number of lines to read

Returns:

A string of at most 10000 bytes, containing at most count newlines.