Skip to content

Conversation

GitToby
Copy link

@GitToby GitToby commented Sep 29, 2025

I tend to have a quick solution to expose my logging with

_ = logger.remove()
_ = logger.add(sys.stderr, format=f"{_defaults.LOGURU_FORMAT} | {{extra}}")

However, accessing private modules is not ideal for code review or API stability. This will expose the format so I can extend it when specifying logging formats.

I'm also thinking this might be nice to have in the formatting step, so that we could define a message as

_ = logger.remove()
_ = logger.add(sys.stderr, format="{defalt_format} | {extra}")

Thoughts welcome - could just be a me thing.

extract the default format to var DEFAULT_FORMAT
expose the DEFAULT_FORMAT as part of the package.
@Delgan
Copy link
Owner

Delgan commented Sep 29, 2025

Hi.

Thanks for the suggestion but the default format isn't meant to be exposed publicly. Instead, I suggest copy-pasting it from source and simply updating it according to your preferences. If this proves too repetitive in the long run, you can also define the environment variable LOGURU_FORMAT once and for all.

Otherwise, you can hack your way around using the built-in inspect module:

default_format = inspect.signature(logger.add).parameters["format"].default

Note that I eventually plan to make {extra} field part of the default format

@GitToby
Copy link
Author

GitToby commented Sep 30, 2025

gotcha - it really is just to expose the extras in the default format.

its a super neat struct logging approach, which we have to expose every time I init a program.

Is there an issue or something for the {extra} field to be part of the default format? I'd be happy to give it a crack and open a PR.

@GitToby GitToby closed this Sep 30, 2025
@Delgan
Copy link
Owner

Delgan commented Sep 30, 2025

The following ticket could be considered related: #1200.

But for now, there are only preliminary discussions, no precise specifications. It's actually more complicated than it looks like, because it's tied to the API change I'm planning for *args / **kwargs and the separation with bind() / contextualize(). All this to pivote toward better structured logging support. To be fair, there is still some side work to be done before a PR could be envisaged.

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

Successfully merging this pull request may close these issues.

2 participants