-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature: add an option for a custom formatter in logging setup #10
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
Usage example with # app.py
import clapper.click
import clapper.logging
import click
import colorlog
main_logger = clapper.logging.setup(
logger_name="awesome",
formatter=colorlog.ColoredFormatter(
fmt="%(log_color)s[%(levelname)s] %(message)s (%(name)s, %(asctime)s)"
),
)
main_logger.setLevel("ERROR")
@click.command(
entry_point_group="cli_group",
cls=clapper.click.ConfigCommand,
)
@click.option(
"--my-config",
"-c",
"my_config",
entry_point_group="config_group",
cls=clapper.click.ResourceOption,
)
@clapper.click.verbosity_option(
main_logger,
expose_value=False,
) # The logger level is set here if -v is given
def awesome_cli(my_config: list[str] | None, **kwargs):
"""My Awesome CLI."""
main_logger.error("App error sample (all is well).")
main_logger.warning("App warning sample (all is well).")
main_logger.info(f"App info sample: {my_config=}")
main_logger.debug("App debug sample: Now exiting CLI app.")
if __name__ == "__main__":
awesome_cli() |
a8b0f98
to
85c7afc
Compare
Beautiful! Looking great, thanks! |
85c7afc
to
49d3c86
Compare
Allow the user to provide a custom formatter class to replace the default `logging.Formatter`. This should allow more flexibility to customize the logs output. The `format` argument is kept for backward compatibility.
Test that the user can set a custom formatter in `clapper.logging.setup`
6938626
to
8b8c3ec
Compare
We can include this in the upcoming release, too. |
anjos
approved these changes
Sep 26, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allow users to provide their own formatter instead of just a format string, allowing further customization of the logs.
Fixes #8.
📚 Documentation preview 📚: https://clapper--10.org.readthedocs.build/en/10/