-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
Add --use-colors
/ --no-use-colors
flags.
#502
Conversation
uvicorn/config.py
Outdated
log_level=None, | ||
access_log=True, | ||
use_colors=True, |
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.
We should default this to None
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.
done
uvicorn/config.py
Outdated
@@ -57,12 +57,12 @@ | |||
SSL_PROTOCOL_VERSION = getattr(ssl, "PROTOCOL_TLS", ssl.PROTOCOL_SSLv23) | |||
|
|||
|
|||
LOGGING_CONFIG = { | |||
LOGGING_CONFIG_COLORS = { |
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.
Let's just stick with a single LOGGING_CONFIG
.
We can pass an argument "use_colors": None,
in the config to the DefaultFormatter
, to indicate that it should be autodetermined.
If use_colors=[True|False] is pass to the config, then we should update just that bit in the config dictionary.
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.
done
uvicorn/config.py
Outdated
@@ -215,10 +250,15 @@ def __reduce__(self): | |||
logging.Logger.__reduce__ = __reduce__ | |||
|
|||
if self.log_config is not None: | |||
if not self.use_colors: | |||
self.log_config = LOGGING_CONFIG_NO_COLORS |
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.
Instead of switching the entire config here, lets use...
if self.use_colors in (True, False):
self.log_config["formatters"]["default"]["use_colors"] = self.use_colors
We should only do this within the if isinstance(self.log_config, dict):
case. If someone is using the file config then it's up to them to choose the correct settings there.
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.
added the same logic for access too
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.
Great stuff!
I've got a bit of a requested tweak in how in think we should handle this... let me know if I've not explained something clearly enough here!
hopefully I got this right ;) |
uvicorn/config.py
Outdated
logging.config.dictConfig(self.log_config) | ||
else: | ||
logging.config.fileConfig(self.log_config) | ||
else: | ||
pass |
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.
Doesn't look like we need the else: pass
block here.
uvicorn/logging.py
Outdated
def __init__(self, fmt=None, datefmt=None, style="%"): | ||
self.use_colors = self.should_use_colors() | ||
def __init__(self, fmt=None, datefmt=None, style="%", use_colors=None): | ||
self.use_colors = use_colors |
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.
We'd want to do...
if use_colors in (True, False):
self.use_colors = use_colours
else:
self.use_colors = sys.stdout.isatty()
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.
Yes, great stuff!
Just a coupla minor comments to address.
Fantastic!
|
yes sorry I forgot the docs, will do that asap |
just one thing, I modified the cli flag too as it was wrong (it was also I'm not sure but think the huge diff in the |
added some examples of custom logging config for #491 edit: commit message wanted to link 491 not 409 |
Okay - Let's drop those out of this pull request. We may want a PR for them, but that's a seperate issue, and I'd prefer to review it in isolation to the rest of this work. |
ok I'm no git pro but I think this might be ok, I did so now colors branch should be in the state it was before adding the examples, |
docs/deployment.md
Outdated
--log-level [critical|error|warning|info|debug|trace] | ||
Log level. [default: info] | ||
--access-log / --no-access-log Enable/Disable access log. | ||
--use-colors / --use-colors Enable/Disable colorized logging. |
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.
Looks like this should be --use-colors / --no-use-colors
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.
ok I was sure I pasted it....now I'm sure
docs/index.md
Outdated
--log-level [critical|error|warning|info|debug|trace] | ||
Log level. [default: info] | ||
--access-log / --no-access-log Enable/Disable access log. | ||
--use-colors / --use-colors Enable/Disable colorized logging. |
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.
Presumably --use-colors / --no-use-colors
, right?
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.
same...
docs/settings.md
Outdated
@@ -30,6 +30,7 @@ equivalent keyword arguments, eg. `uvicorn.run("example:app", port=5000, reload= | |||
* `--log-config <path>` - Logging configuration file. | |||
* `--log-level <str>` - Set the log level. **Options:** *'critical', 'error', 'warning', 'info', 'debug', 'trace'.* **Default:** *'info'*. | |||
* `--no-access-log` - Disable access log only, without changing log level. | |||
* `--use-colors` - Enable colorized formatting of the log records. |
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.
We should change this doc around so that:
- We include both the "on" and "off" flag variants.
- It's clear that we'll autodetect if the flag isn't used.
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.
changed, let me know if this is better
Looks okay to me, yup. As it happens you don't actually need to do those smarts - we have a policy of squashing changes down into a single-commit-per-pull-request on merges, so we don't get any of the messy "getting towards the goal" individual commits, but instead just have a single "here's the PR functionality" commit in the history. You'd be absolutely fine just making a new commit that removed the work we didn't want in here. |
--use-colors
/ --no-use-colors
flags.
Thanks for this! |
I think I somewhat f*** up this PR by fogetting to add the new flag in the main() @tomchristie tthe below patch should fix it I think, not sure how to proceed from here
|
Looks right to me too. Wanna issue a PR for that? |
Will do for sure tomorrow!
Le mar. 10 déc. 2019 à 10:48 PM, Tom Christie <[email protected]> a
écrit :
… the below patch should fix it I think
Looks right to me too. Wanna issue a PR for that?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#502?email_source=notifications&email_token=AAINSPSMOX5OQLAEV2FPW2DQYAFBDA5CNFSM4JTHMIRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGRCG6I#issuecomment-564274041>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAINSPSRQGT5MFVYVZCY6M3QYAFBDANCNFSM4JTHMIRA>
.
|
ok done in #520 |
A potential attempt at #497
I wish I could have found a way to add tests but I have no idea as to what to test, I can see if I pass the
use_colors
flag to False that it's working but that's weakTrue
False