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

Document use of logging for plugin authors #3449

Open
5 tasks
ssbarnea opened this issue Nov 19, 2024 · 0 comments
Open
5 tasks

Document use of logging for plugin authors #3449

ssbarnea opened this issue Nov 19, 2024 · 0 comments

Comments

@ssbarnea
Copy link
Member

ssbarnea commented Nov 19, 2024

Issue

There is no documentation for how plugin authors should make use of python logging in order to integrate nicely with tox own logging. The use of standard python logging is great but there are some tox specific details that might confuse plugin authors.

Once I get the behavior identified and a good example, I will make a PR to add this to the documentation and close this ticket.

Minimal example

# plugin code

import logging

# you could use getLogger and have your own instance but it does not
# have any apparent visible changes.

# should produce a line visible only when using -v or more
logging.info("%s%s> %s", "", __package__, "this is a message")

# should produce a warning line, potentially using the cyan prefix colorer if msg is ``%s%s> %s`
logging.warning("%s%s> %s", "", __package__, "this is a message")

# produce an error, colored in red if ansi enabled but without
logging.error("%s%s> %s", "", __package__, "this is a message")

Identified challenges:

  • logging level is not visible in output, only the coloring determines it (potential accessibility issue)
  • info level is not displayed by default
  • warning level is using a normal color, not yellow/orange. If you want to make some output on default logging you are forced to use warning, even if what you mean is probably a "notice"
  • unable to colorize "error" lines (cyan prefix works only for warning)
  • if you want to include plugin name, you have to use something like below:
logging.warning("%s%s> %s", "", __package__, f"This is a message from {__package__} plugin")
logging.error("%s%s> %s", "", __package__, f"This is a message from {__package__} plugin")

# ^ this is possible only for warning, if you try to log error, you cannot colorize the plugin name as the entire line will be re
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant