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

level with fix width #1230

Open
mischlrebl opened this issue Nov 6, 2024 · 2 comments
Open

level with fix width #1230

mischlrebl opened this issue Nov 6, 2024 · 2 comments
Labels
question Further information is requested

Comments

@mischlrebl
Copy link

thank you for the very useful tool.

is it possible to write the level with a fix width of chars into a file? appreviated with 4, or padded to 7, ....
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {message}"

@Delgan
Copy link
Owner

Delgan commented Nov 11, 2024

Hi @mischlrebl.

This is indeed possible. You can define the abbreviated level name, and use it in a custom format.

import sys
from loguru import logger


def formatter(record):
    record["extra"]["short_level_name"] = record["level"].name[:4]
    return "{time:YYYY-MM-DD HH:mm:ss.SSS} | {extra[short_level_name]} | {message}\n{exception}"


logger.remove()
logger.add(sys.stderr, format=formatter)


logger.warning("Test")

@Delgan Delgan added the question Further information is requested label Nov 11, 2024
@trim21
Copy link
Contributor

trim21 commented Nov 12, 2024

you can use Python's format style to do padding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants