Skip to content

Allow format string to be set in handler #59

Closed
@bendavis78

Description

@bendavis78

Right now the log handler has a fixed format:

    def format(self, record: LogRecord) -> str:
        """Generate a timestamped message.

        :param record: The record (message object) to be logged
        """

        return f"{record.created:<0.3f}: {record.levelname} - {record.msg}"

The only way to customize this format is to subclass the handler. It would be more convienient to just be able to set the format string at the time the handler is initialized, eg:

log_handler = StreamHandler(format_str="[%(asctime)s] %(levelname)s: %(message)s")

Better yet, it would be nice to just mimic the way python does formatters:

formatter = logging.Formatter(fmt="[%(asctime)s] %(levelname)s: %(message)s")
log_handler = StreamHandler(fmt=formatter)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions