Skip to content

Commit 275b33d

Browse files
authored
Merge pull request #532 from CodeForPhilly/494-logging
Format logs on server
2 parents b8e6d41 + be26834 commit 275b33d

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed

src/client/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RUN npm run build
2323
FROM nginx:latest AS host
2424

2525
# COPY nginx-client.conf /etc/nginx/conf.d/default.conf
26+
COPY nginx.conf /etc/nginx/nginx.conf
2627
COPY default.conf.template /etc/nginx/templates/
2728

2829
COPY --from=builder /app/build/ /usr/share/nginx/html

src/client/nginx.conf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
http {
13+
include /etc/nginx/mime.types;
14+
default_type application/octet-stream;
15+
16+
log_format json_combined escape=json
17+
'{'
18+
'"timestamp":"$msec",'
19+
'"address":"$remote_addr",'
20+
'"request":"$request",'
21+
'"body_bytes_sent":$body_bytes_sent,'
22+
'"response_status":$status,'
23+
'"http_user_agent":"$http_user_agent"'
24+
'}';
25+
26+
access_log /var/log/nginx/access.log json_combined;
27+
28+
sendfile on;
29+
30+
keepalive_timeout 65;
31+
32+
include /etc/nginx/conf.d/*.conf;
33+
34+
server {
35+
listen 80;
36+
server_name localhost;
37+
client_max_body_size 100M;
38+
39+
location ^~ /api/internal { # Blocks external access to /api/internal/*
40+
return 404;
41+
}
42+
43+
44+
45+
location / {
46+
root /usr/share/nginx/html;
47+
index index.html index.htm;
48+
try_files $uri /index.html; # forward all requests to the index.html for react
49+
}
50+
51+
location /api {
52+
try_files $uri @backend;
53+
}
54+
55+
location @backend {
56+
proxy_pass http://backend;
57+
proxy_set_header X-Real-IP $remote_addr;
58+
proxy_set_header Host $host;
59+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
60+
proxy_read_timeout 3600;
61+
proxy_connect_timeout 3600;
62+
proxy_send_timeout 3600;
63+
send_timeout 3600;
64+
}
65+
}
66+
}

src/server/bin/startServer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ echo "SLEEPING.. WAITING FOR DB"; sleep 5; echo "WAKING"; alembic upgrade head;
1111

1212
# --no-reload prevents Flask restart, which usually happens in middle of create_base_users()
1313
#TODO: SECURITY - ensure we are not running in debug mode in production
14-
uwsgi --http-socket :5000 --plugin python38 --module wsgi:app --chdir /app --pythonpath . --processes 2 --threads 4 --master
14+
uwsgi bin/uwsgi.ini

src/server/bin/uwsgi.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[uwsgi]
2+
http-socket = :5000
3+
plugin = python38
4+
module = wsgi:app
5+
chdir = /app
6+
pythonpath = .
7+
processes = 2
8+
threads = 4
9+
log-4xx = true
10+
log-5xx = true
11+
disable-logging = true
12+
logformat = {"timestamp": "%(tmsecs)", "address": "%(addr)", "method": "%(method)", "protocol": "%(proto)", "resp_size": "%(size)", "request_body_size": "%(cl)", "response_status": "%(status)", "response_time": "%(secs)", "uri": "%(uri)"}
13+
logformat-strftime = true

src/server/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
structlog.processors.add_log_level,
1818
structlog.processors.StackInfoRenderer(),
1919
structlog.dev.set_exc_info,
20-
structlog.processors.TimeStamper(fmt="iso", utc=True ),
20+
structlog.processors.TimeStamper(fmt=None, utc=True ),
2121
structlog.processors.CallsiteParameterAdder(
2222
[
2323
CallsiteParameter.FILENAME,

0 commit comments

Comments
 (0)