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

Align log message types #49

Open
johnthagen opened this issue Mar 21, 2018 · 1 comment
Open

Align log message types #49

johnthagen opened this issue Mar 21, 2018 · 1 comment

Comments

@johnthagen
Copy link
Contributor

The default log format misaligns log messages of different types:

2015-10-23 03:32:22 peter-macbook coloredlogs.demo[30462] DEBUG message with level 'debug'
2015-10-23 03:32:23 peter-macbook coloredlogs.demo[30462] VERBOSE message with level 'verbose'
2015-10-23 03:32:24 peter-macbook coloredlogs.demo[30462] INFO message with level 'info'

It would be great if by default coloredlogs worked like:

2015-10-23 03:32:22 peter-macbook coloredlogs.demo[30462] DEBUG   message with level 'debug'
2015-10-23 03:32:23 peter-macbook coloredlogs.demo[30462] VERBOSE message with level 'verbose'
2015-10-23 03:32:24 peter-macbook coloredlogs.demo[30462] INFO    message with level 'info'
@johnthagen johnthagen changed the title Align log message types of different type Align log message types Mar 21, 2018
@metov
Copy link

metov commented Jun 18, 2021

You can get this behavior with a custom log format since those use the old printf-style formatting syntax.

import coloredlogs
import logging

log = logging.getLogger(__name__)

# Figure out the how long the field needs to be
w = max(len(s) for s in coloredlogs.find_defined_levels().keys())

# Specify minimum width in the log format
coloredlogs.install(
    level="DEBUG", logger=log, fmt=f"%(filename)s %(levelname)-{w}s %(message)s"
)

# Print some logs
log.debug("Don't mind me")
log.info("Just testing logs")
log.warning("Not sure if this will work")
log.error("Actually I should probably check first")
log.critical("Let me do that and come back")

logs

I agree that it would be a nice default though.

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