litestar icon indicating copy to clipboard operation
litestar copied to clipboard

Add log_config and rich_logging attribs to app

Open john-ingles opened this issue 3 years ago • 6 comments

Adds two new instance attributes to starlite.app.Starlite class.

  1. log_config - Takes in a dict of config options to pass to logging.dictConfig. Allows custom log configuration by the user.
  2. rich_logging - Default False. If True, swaps out the default console log handler with a RichHandler. If rich isn't present when rich_logging = True, raises an ImproperlyConfiguredException

PR Checklist

  • [ ] Have you followed the guidelines in CONTRIBUTING.md?
  • [ ] Have you got 100% test coverage on new code?
  • [ ] Have you updated the prose documentation?
  • [ ] Have you updated the reference documentation?

I'll probably need some help writing tests and docs for this assuming there are no changes needed.

john-ingles avatar Sep 11 '22 05:09 john-ingles

@Goldziher Thanks for the feedback. I'll work on those. In the mean time, any advice on getting through the pre-commit checks? Looks like we might need to increase the number of allowed parameters to a function as well tell it not to worry about rich not being resolvable. Is there a better way of checking to see if rich is installed than importing it? Importlib?

john-ingles avatar Sep 11 '22 13:09 john-ingles

@Goldziher Thanks for the feedback. I'll work on those. In the mean time, any advice on getting through the pre-commit checks? Looks like we might need to increase the number of allowed parameters to a function as well tell it not to worry about rich not being resolvable. Is there a better way of checking to see if rich is installed than importing it? Importlib?

For pylint - you can add too-many-statements to the disabled rules section for pylint in pyproject.toml:

[tool.pylint.MESSAGE_CONTROL]
disable = [
...
]

As for checking if something is installed - its standard practice to try to import something and catch ImportError. E.g.:

try:
   from rich import x
except ImportError:
   x = None

You can then test if x: etc.

Goldziher avatar Sep 11 '22 13:09 Goldziher

whats the status of this?

Goldziher avatar Sep 17 '22 17:09 Goldziher

whats the status of this?

I've been waiting to see what will happen with the logging middleware #411 . It looked like it was going to be merged soon and might have implications for this that might require big changes. In the mean time, do you have any advice for the failing tests?

john-ingles avatar Sep 17 '22 21:09 john-ingles

Let's proceed with this one. Regardless of the other PR.

I'll look at the tests.

Goldziher avatar Sep 18 '22 07:09 Goldziher

@john-ingles - you can rebase on main. It should fix the issue in CI

Goldziher avatar Sep 20 '22 16:09 Goldziher

I think I'll close this draft because of #511's submission.

john-ingles avatar Sep 23 '22 18:09 john-ingles

As you wish. I think you can add a simple PR for rich logging based on it. I am about to update it shortly.

Goldziher avatar Sep 23 '22 20:09 Goldziher