Skip to content

Format logs on server #532

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

Merged
merged 14 commits into from
Dec 31, 2023
Merged

Format logs on server #532

merged 14 commits into from
Dec 31, 2023

Conversation

osabahat
Copy link
Collaborator

@osabahat osabahat commented Jan 3, 2023

Formats the uwsgi output on the server. Example after launching the app:

$ curl localhost/api/user/test

paws-compose-server  | { "host": "localhost", "address": "172.18.0.4", "method": "GET", "protocol": "HTTP/1.0", "resp_size": "104", "request_body_size": "0", "response_status": "500", "response_time": "0.000251", "uri": "/api/user/test"}

The full list of options for uwsgi logging flags can be found in the docs:
https://uwsgi-docs.readthedocs.io/en/latest/LogFormat.html

@osabahat osabahat requested a review from c-simpson January 3, 2023 04:04
@c-simpson
Copy link
Collaborator

@osabahat Can you update this for 3.11?

@osabahat
Copy link
Collaborator Author

osabahat commented Feb 6, 2023

@osabahat Can you update this for 3.11?

@c-simpson
I did try 3.11 and 3.12 but the container isn't building the uwsgi python plugin properly, getting a gcc error. I tried installing a couple different versions in the container since the latest one wasn't working but didn't have much luck.

@c-simpson
Copy link
Collaborator

Osman,

Looking at your log lines:

{ "host": "localhost:5000",    
"address": "172.18.0.1", "method": "GET", "protocol": "HTTP/1.1",    
"resp_size": "153", "request_body_size": "0", "response_status": "200",    
"response_time": "0.005398", "uri": "/api/user/test"   
}

I don't think that "host" gives much value as it will be added by the log collector.
I think they do want a log level for filtering, one of fatal, error, warn, info, debug, trace like "level":"debug" . Maybe log 200s at 'debug' and errors at higher levels by severity?

On the server logging we've got a timestamp like "timestamp": "2023-03-04T20:50:18.774619Z". Do you have a way to add that to enable correlation?

@osabahat
Copy link
Collaborator Author

osabahat commented Apr 10, 2023

I removed the hostname field and added a timestamp field formatted the same way as the server logging with the exception of milliseconds (strftime() does not support milliseconds).

I also changed uwsgi's behavior so that by default it will only log 400/500 errors. In order to change this to display other logs, one would need to delete the disable-logging option in the config file. I don't think there's a way for uwsgi to know what the log level of the program is and filtering based on that, as log levels are specific to the Python logging module being used.

Here's a prettified example hitting /api/user/test_fail:

{
"timestamp": "2023-04-10-T02:17:11Z", 
"address": "192.168.80.4", 
"method": "GET", 
"protocol": "HTTP/1.0", 
"resp_size": "135", 
"request_body_size": "0", 
"response_status": "401", 
"response_time": "0.000953", 
"uri": "/api/user/test_fail"
}

@osabahat
Copy link
Collaborator Author

Change "timestamp" format to milliseconds from epoch with %(tmsecs)

@osabahat osabahat mentioned this pull request Dec 6, 2023
@c-simpson c-simpson merged commit 275b33d into master Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants