Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow format string to be set in handler #59

Closed
bendavis78 opened this issue Jun 19, 2024 · 2 comments
Closed

Allow format string to be set in handler #59

bendavis78 opened this issue Jun 19, 2024 · 2 comments

Comments

@bendavis78
Copy link

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)
@FoamyGuy
Copy link
Contributor

FoamyGuy commented Aug 6, 2024

#61 adds support for Formatter objects and setFormatter() on the Handler class.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Oct 2, 2024

resolved by #61

@FoamyGuy FoamyGuy closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants