fix exception during logging
This commit is contained in:
parent
4394e58cd3
commit
4d0a42887f
1 changed files with 34 additions and 74 deletions
|
|
@ -1,21 +1,16 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import ssl
|
|
||||||
import string
|
|
||||||
import random
|
|
||||||
import bumper
|
|
||||||
import os
|
|
||||||
from bumper.models import *
|
|
||||||
from bumper import plugins
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from aiohttp import web
|
import logging
|
||||||
|
import os
|
||||||
|
import ssl
|
||||||
|
|
||||||
import aiohttp_jinja2
|
import aiohttp_jinja2
|
||||||
import jinja2
|
import jinja2
|
||||||
import uuid
|
from aiohttp import web
|
||||||
import xml.etree.ElementTree as ET
|
|
||||||
|
from bumper import plugins
|
||||||
|
from bumper.models import *
|
||||||
|
|
||||||
|
|
||||||
class aiohttp_filter(logging.Filter):
|
class aiohttp_filter(logging.Filter):
|
||||||
|
|
@ -216,8 +211,18 @@ class ConfServer:
|
||||||
async def log_all_requests(self, request, handler):
|
async def log_all_requests(self, request, handler):
|
||||||
|
|
||||||
if request._match_info.route.name not in self.excludelogging:
|
if request._match_info.route.name not in self.excludelogging:
|
||||||
|
to_log = {
|
||||||
|
"request": {
|
||||||
|
"route_name": f"{request.match_info.route.name}",
|
||||||
|
"method": f"{request.method}",
|
||||||
|
"path": f"{request.path}",
|
||||||
|
"query_string": f"{request.query_string}",
|
||||||
|
"raw_path": f"{request.raw_path}",
|
||||||
|
"raw_headers": f'{",".join(map("{}".format, request.raw_headers))}',
|
||||||
|
}
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
|
postbody = None
|
||||||
if request.content_length:
|
if request.content_length:
|
||||||
if request.content_type == "application/x-www-form-urlencoded":
|
if request.content_type == "application/x-www-form-urlencoded":
|
||||||
postbody = await request.post()
|
postbody = await request.post()
|
||||||
|
|
@ -231,78 +236,33 @@ class ConfServer:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
postbody = await request.post()
|
postbody = await request.post()
|
||||||
else:
|
|
||||||
postbody = None
|
to_log["request"]["body"] = postbody
|
||||||
|
|
||||||
response = await handler(request)
|
response = await handler(request)
|
||||||
|
if response is None:
|
||||||
|
confserverlog.warning("Response was null!")
|
||||||
|
confserverlog.warning(json.dumps(to_log))
|
||||||
|
return response
|
||||||
|
|
||||||
|
to_log["response"] = {
|
||||||
|
"status": f"{response.status}",
|
||||||
|
}
|
||||||
if not "application/octet-stream" in response.content_type:
|
if not "application/octet-stream" in response.content_type:
|
||||||
logall = {
|
to_log["response"]["status"] = f"{response.status}"
|
||||||
"request": {
|
|
||||||
"route_name": f"{request.match_info.route.name}",
|
|
||||||
"method": f"{request.method}",
|
|
||||||
"path": f"{request.path}",
|
|
||||||
"query_string": f"{request.query_string}",
|
|
||||||
"raw_path": f"{request.raw_path}",
|
|
||||||
"raw_headers": f'{",".join(map("{}".format, request.raw_headers))}',
|
|
||||||
"body": f"{postbody}",
|
|
||||||
},
|
|
||||||
|
|
||||||
"response": {
|
confserverlog.debug(json.dumps(to_log))
|
||||||
"response_body": f"{json.loads(response.body)}",
|
|
||||||
"status": f"{response.status}",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
logall = {
|
|
||||||
"request": {
|
|
||||||
"route_name": f"{request.match_info.route.name}",
|
|
||||||
"method": f"{request.method}",
|
|
||||||
"path": f"{request.path}",
|
|
||||||
"query_string": f"{request.query_string}",
|
|
||||||
"raw_path": f"{request.raw_path}",
|
|
||||||
"raw_headers": f'{",".join(map("{}".format, request.raw_headers))}',
|
|
||||||
"body": f"{postbody}",
|
|
||||||
},
|
|
||||||
|
|
||||||
"response": {
|
|
||||||
"status": f"{response.status}",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
confserverlog.debug(json.dumps(logall))
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except web.HTTPNotFound as notfound:
|
except web.HTTPNotFound as notfound:
|
||||||
confserverlog.debug("Request path {} not found".format(request.raw_path))
|
confserverlog.debug("Request path {} not found".format(request.raw_path))
|
||||||
requestlog = {
|
confserverlog.debug(json.dumps(to_log))
|
||||||
"request": {
|
|
||||||
"route_name": f"{request.match_info.route.name}",
|
|
||||||
"method": f"{request.method}",
|
|
||||||
"path": f"{request.path}",
|
|
||||||
"query_string": f"{request.query_string}",
|
|
||||||
"raw_path": f"{request.raw_path}",
|
|
||||||
"raw_headers": f'{",".join(map("{}".format, request.raw_headers))}',
|
|
||||||
"body": f"{postbody}",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
confserverlog.debug(json.dumps(requestlog))
|
|
||||||
return notfound
|
return notfound
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
confserverlog.exception("{}".format(e))
|
confserverlog.exception("{}".format(e))
|
||||||
requestlog = {
|
confserverlog.error(json.dumps(to_log))
|
||||||
"request": {
|
|
||||||
"route_name": f"{request.match_info.route.name}",
|
|
||||||
"method": f"{request.method}",
|
|
||||||
"path": f"{request.path}",
|
|
||||||
"query_string": f"{request.query_string}",
|
|
||||||
"raw_path": f"{request.raw_path}",
|
|
||||||
"raw_headers": f'{",".join(map("{}".format, request.raw_headers))}',
|
|
||||||
"body": f"{postbody}",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
confserverlog.debug(json.dumps(requestlog))
|
|
||||||
return e
|
return e
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue