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

add extra to default text output format #1200

Open
trim21 opened this issue Sep 11, 2024 · 3 comments
Open

add extra to default text output format #1200

trim21 opened this issue Sep 11, 2024 · 3 comments
Labels
feature Request for adding a new feature

Comments

@trim21
Copy link
Contributor

trim21 commented Sep 11, 2024

This is a suggestion to change default loguru text output format, or a new option to append extra to non-serialized text format.

There are many structured logging will include extra to text output, but loguru just ignore them.

Hope loguru could support this. For example, append key1=value1 key2=value2 to default text output.

so a code snippet will output 2024-09-12 00:17:01.261 | INFO | __main__:<module>:5 - hello world task=main pid=1

from loguru import logger


with logger.contextualize(task="main", pid=1):
    logger.info("hello world")

golang stdlib log/slog:

2022/11/08 15:28:26 INFO hello count=3

zerolog(golang)
image

pino(nodejs)
image

structlog(python)
image

@Delgan Delgan added the feature Request for adding a new feature label Sep 22, 2024
@Delgan
Copy link
Owner

Delgan commented Sep 22, 2024

Thanks for the comparison with different frameworks. That's very helpful.

I'd already thought about it and I'm all for it. Structured logging is the way to go.

My plan is to add a new entry to the log record, for example a data dict. This would be filled by the keyword arguments of the logged message instead of extra currently. This is because it should be viewed as semantically different.

Then, add {data} to the current default format, which would be nicely formatted (if non-empty), e.g.:

logger.info("Hello world", foo="bar", baz=123)
# => 2024-09-22 19:39:58.381 | INFO     | __main__:<module>:1 - Hello world (foo="bar", baz=123)

@trim21
Copy link
Contributor Author

trim21 commented Sep 22, 2024

will kwargs from logger.contextualize be included?

@Delgan
Copy link
Owner

Delgan commented Sep 22, 2024

Initially, I believed it should not, but maybe I'm wrong. I haven't given it enough thought. I need to look into the current usage made of contextualize() in relation to bind().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request for adding a new feature
Projects
None yet
Development

No branches or pull requests

2 participants