sample uWSGI logging
- added source identifier to application logs - added toy NGINX/uWSGI setup in sample directory
This commit is contained in:
parent
300199202a
commit
a86751e010
@ -34,7 +34,7 @@ class JsonFormatter(logging.Formatter):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
message_dict = {}
|
message_dict = {"source": "atst"}
|
||||||
for field, func in self._DEFAULT_RECORD_FIELDS:
|
for field, func in self._DEFAULT_RECORD_FIELDS:
|
||||||
message_dict[field] = func(record)
|
message_dict[field] = func(record)
|
||||||
|
|
||||||
|
2
sample-config/Procfile
Normal file
2
sample-config/Procfile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
uwsgi: LOG_JSON=true DEBUG=false uwsgi --ini sample-config/uwsgi.ini
|
||||||
|
nginx: nginx -c $(pwd)/sample-config/nginx.conf
|
50
sample-config/nginx.conf
Normal file
50
sample-config/nginx.conf
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
daemon off;
|
||||||
|
|
||||||
|
error_log /dev/stdout;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
default_type application/octet-stream;
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 8000;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
access_log /dev/stdout;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri @app;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @app {
|
||||||
|
uwsgi_pass uwsgi://localhost:8080;
|
||||||
|
uwsgi_param QUERY_STRING $query_string;
|
||||||
|
uwsgi_param REQUEST_METHOD $request_method;
|
||||||
|
uwsgi_param CONTENT_TYPE $content_type;
|
||||||
|
uwsgi_param CONTENT_LENGTH $content_length;
|
||||||
|
|
||||||
|
uwsgi_param REQUEST_URI $request_uri;
|
||||||
|
uwsgi_param PATH_INFO $document_uri;
|
||||||
|
uwsgi_param DOCUMENT_ROOT $document_root;
|
||||||
|
uwsgi_param SERVER_PROTOCOL $server_protocol;
|
||||||
|
uwsgi_param REQUEST_SCHEME $scheme;
|
||||||
|
uwsgi_param HTTPS $https if_not_empty;
|
||||||
|
|
||||||
|
uwsgi_param REMOTE_ADDR $remote_addr;
|
||||||
|
uwsgi_param REMOTE_PORT $remote_port;
|
||||||
|
uwsgi_param SERVER_PORT $server_port;
|
||||||
|
uwsgi_param SERVER_NAME $server_name;
|
||||||
|
uwsgi_param HTTP_X_REQUEST_ID $request_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
sample-config/uwsgi.ini
Normal file
25
sample-config/uwsgi.ini
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
[uwsgi]
|
||||||
|
; general uWSGI config for sample
|
||||||
|
callable = app
|
||||||
|
module = app
|
||||||
|
plugin = python3
|
||||||
|
socket = localhost:8080
|
||||||
|
|
||||||
|
; logger config
|
||||||
|
|
||||||
|
; application logs: log without modifying
|
||||||
|
logger = secondlogger stdio
|
||||||
|
log-route = secondlogger atst
|
||||||
|
log-encoder = format:secondlogger ${msg}
|
||||||
|
|
||||||
|
; default uWSGI messages (start, stop, etc.)
|
||||||
|
logger = default stdio
|
||||||
|
log-route = default ^((?!atst).)*$
|
||||||
|
log-encoder = json:default {"timestamp":"${strftime:%%FT%%T}","source":"uwsgi","severity":"DEBUG","message":"${msg}"}
|
||||||
|
log-encoder = nl
|
||||||
|
|
||||||
|
; uWSGI request logs
|
||||||
|
logger-req = stdio
|
||||||
|
log-format = request_id=%(var.HTTP_X_REQUEST_ID), pid=%(pid), remote_add=%(addr), request=%(method) %(uri), status=%(status), body_bytes_sent=%(rsize), referer=%(referer), user_agent=%(uagent), http_x_forwarded_for=%(var.HTTP_X_FORWARDED_FOR)
|
||||||
|
log-req-encoder = json {"timestamp":"${strftime:%%FT%%T}","source":"req","severity":"INFO","message":"${msg}"}
|
||||||
|
log-req-encoder = nl
|
Loading…
x
Reference in New Issue
Block a user