-
-
Notifications
You must be signed in to change notification settings - Fork 723
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
Logging custom docs #515
Logging custom docs #515
Changes from 5 commits
33c2c9c
b2d4f12
3fab8e5
4da9f50
588c590
02bf10f
0c263b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Examples | ||
|
||
## Custom logging | ||
|
||
The below `logging_example.yaml` is a yaml representation of the default logging configuration. | ||
You can pass it loading a dict, using the `--log-config` flag. | ||
It sets 2 loggers: | ||
1. `uvicorn.error` whose formatter is the `uvicorn.logging.DefaultFormatter`. | ||
2. `uvicorn.access` whose formatter is the `uvicorn.logging.AccessFormatter`. | ||
|
||
Both formatters will output a colorized automatically if a tty is detected. | ||
|
||
If you used the `--use-colors / --no-use-colors` then the output will / won't be colorized. | ||
|
||
```yaml hl_lines="7 11 38 39 40 41" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather than any example is just included directly, than using this style. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok so you prefer to remove markdown-include and just copy-paste examples right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{!./src/logging_example/logging_example.yaml!} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: 1 | ||
disable_existing_loggers: False | ||
formatters: | ||
default: | ||
"()": uvicorn.logging.DefaultFormatter | ||
format: "%(levelprefix)s %(message)s" | ||
access: | ||
"()": uvicorn.logging.AccessFormatter | ||
format: '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s' | ||
handlers: | ||
default: | ||
formatter: default | ||
class: logging.StreamHandler | ||
stream: ext://sys.stdout | ||
access: | ||
formatter: access | ||
class: logging.StreamHandler | ||
stream: ext://sys.stdout | ||
loggers: | ||
uvicorn.error: | ||
level: INFO | ||
handlers: | ||
- default | ||
propagate: no | ||
uvicorn.access: | ||
level: INFO | ||
handlers: | ||
- access | ||
propagate: no |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ requests | |
# Documentation | ||
mkdocs | ||
mkdocs-material | ||
markdown-include |
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.
Just checking... Does this definately work?
I haven't checked out if Python's log file format also supports using the yaml style?
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.
this is definitely an ambiguous formulation, python logging supports dict / file (ini style). A lot of time people use yaml and load it to dict with pyyaml for instance, that's why I said "representation"
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.
Right, but it wouldn't directly work with our
--log-config
flag right?(Tho we could potentially change things here, so that we expect a YAML style logging config file.)
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.
correct, one would have to do something like