-
Notifications
You must be signed in to change notification settings - Fork 678
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
Request logging encoding stopped working in 2.0.x #1654
Comments
I'd also be interested to know how to use |
@quantoid did you have any luck with the second part (not encoding your flask app output)? I also found that I had to go back to 2.0.14 to get any of the json encoding to work |
+1 on this, I'm running into the same issues: I'm defining json logger throughout all of our stack, and I cannot make it work on uwsgi. I would say there is two different issues here:
|
Finally solved this today: you have to include |
But still haven’t found a way to stop app logging from being encoded along with other stdout. |
What I think we need here is an option to redirect stdout and stderr from uwsgi itself (but not from the app) to a logger, with the appropriate logging level. Then you can keep control of where all your logging goes and how it gets formatted in the usual python way. The output from the app (and hence from its loggers) should be left alone in this case, because it's probably already output from loggers. I guess I could configure the root logger to just output the message to stdout and rely on uwsgi formatting as logging, but then I lose the name and level attributes. |
I agree; I also found it very difficult to get JSON logs out of uwsgi and
my application together without having the application logs encoded to a
string.
I ended up writing a plugin that defines new logchunks (
http://uwsgi-docs.readthedocs.io/en/latest/LogFormat.html#hacking-logformat)
which JSON encode the request variables that I wanted to output in my logs.
Then I defined my log-format carefully to be a JSON object and used those
new variables. An excerpt:
log-format =
{"src":"uwsgi","msg":{"uri":"%(json_uri)","host":"%(json_host)","uagent":"%(json_user_agent)"
... }}
This makes uwsgi's log messages appear as JSON. Then I configured my python
app to output its logs as JSON, which appear on separate lines from the
uwsgi log messages.
…On Tue, Feb 27, 2018 at 9:04 PM, Mike ***@***.***> wrote:
What I think we need here is for stdout and stderr from uwsgi itself (but
not from the app) to be sent to a logger with the appropriate logging
level. Then you can keep control of where all your logging goes and how it
gets formatted in the usual python way.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1654 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AARhuf81gf6BdYBqXZNesTCO03queexMks5tZMJbgaJpZM4PrYyt>
.
|
I've recently managed to configure uWSGI to output all logs in JSON format and pass-through the application logs (as they are already in JSON format). I also ended up writing a uWSGI logging plugin with custom logchunks. You can read more about it on my blog: https://www.velebit.ai/blog/tech-blog-uwsgi-json-logging/ There is also a link on my repo that contains the source code of my uWSGI plugin and all required instructions to build and use it. |
I'm using the
--log-req-encoder
option to encode request logging as JSON. This has been working fine for a while, but recently stopped having any effect (the logging is now plain text).Options used:
What I see on stdout:
The JSON encoded line is the output from my Flask app, which uses a python log formatter to encode as JSON.
The next line logging the GET request/response used to be JSON encoded but is not any more.
The text was updated successfully, but these errors were encountered: