Added logfile
This commit is contained in:
parent
369084fc48
commit
103f6ab33a
39
game.py
39
game.py
|
@ -1,8 +1,11 @@
|
|||
#! /bin/python3
|
||||
|
||||
from random import choice
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request
|
||||
from configparser import ConfigParser
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import pytz
|
||||
|
||||
app = Flask(__name__,
|
||||
static_url_path='',
|
||||
|
@ -11,6 +14,40 @@ app = Flask(__name__,
|
|||
|
||||
config = ConfigParser()
|
||||
config.read('config.ini')
|
||||
logging.basicConfig(encoding='utf-8', level=logging.INFO)
|
||||
logger = logging.getLogger('waitress')
|
||||
tz = pytz.timezone('Europe/Berlin')
|
||||
|
||||
@app.after_request
|
||||
def log_the_request(response):
|
||||
now = datetime.now(tz=tz)
|
||||
|
||||
if not request.remote_user:
|
||||
remote_user = "-"
|
||||
else:
|
||||
remote_user = request.remote_user
|
||||
|
||||
if not request.referrer:
|
||||
referrer = "-"
|
||||
else:
|
||||
referrer = request.referrer
|
||||
|
||||
log = {
|
||||
'remote_addr': request.remote_addr,
|
||||
'remote_user': remote_user,
|
||||
'url': request.full_path,
|
||||
'date': now.strftime("%d/%b/%Y:%H:%M:%S %z"),
|
||||
'referrer': referrer,
|
||||
'user_agent': request.user_agent.string,
|
||||
'method': request.method,
|
||||
'content_length': response.content_length,
|
||||
'status_code': response.status_code
|
||||
}
|
||||
|
||||
logfile = "{} - {} [{}] \"{} {}\" {} {} \"{}\" \"{}\"".format(log['remote_addr'], log['remote_user'], log['date'], log['method'], log['url'], log['status_code'], log['content_length'], log['referrer'], log['user_agent'])
|
||||
logger.info(logfile)
|
||||
|
||||
return response
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
|
|
|
@ -4,4 +4,6 @@ directory=/opt/ab/
|
|||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stdout_logfile_maxbytes=32MB
|
||||
stdout_logfile_backups=10
|
||||
user=www-data
|
||||
|
|
Loading…
Reference in New Issue