create custom logger to log at debug level webhook requests
This commit is contained in:
parent
21c568312b
commit
17f24cb086
3 changed files with 41 additions and 5 deletions
|
@ -92,18 +92,20 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||||
|
|
||||||
WORKDIR "${PROJECT_DIR}"
|
WORKDIR "${PROJECT_DIR}"
|
||||||
|
|
||||||
|
# Install any native runtime dependencies
|
||||||
|
RUN apk add --no-cache libstdc++
|
||||||
|
|
||||||
# Copy python dependencies from the "builder" container
|
# Copy python dependencies from the "builder" container
|
||||||
COPY --from=builder "${PROJECT_DIR}" "${PROJECT_DIR}"
|
COPY --from=builder "${PROJECT_DIR}" "${PROJECT_DIR}"
|
||||||
|
|
||||||
# Copy libolm from the "builder" container
|
# Copy libolm from the "builder" container
|
||||||
COPY --from=builder /usr/local/lib/libolm* /usr/local/lib/
|
COPY --from=builder /usr/local/lib/libolm* /usr/local/lib/
|
||||||
|
|
||||||
# Install any native runtime dependencies
|
|
||||||
RUN apk add --no-cache libstdc++
|
|
||||||
|
|
||||||
# Specify a volume that holds the config file, SQLite3 database,
|
# Specify a volume that holds the config file, SQLite3 database,
|
||||||
# and the matrix-nio store
|
# and the matrix-nio store
|
||||||
VOLUME ["/data"]
|
VOLUME ["/data"]
|
||||||
|
|
||||||
# Start the bot
|
# Start the bot
|
||||||
CMD ["matrix-alertbot", "/data/config.yaml"]
|
CMD ["matrix-alertbot", "/data/config.yaml"]
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
|
@ -40,6 +40,8 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- matrix-alertbot
|
- matrix-alertbot
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
volumes:
|
volumes:
|
||||||
- matrix-alertbot:/data
|
- matrix-alertbot:/data
|
||||||
# Used for allowing connections to homeservers hosted on the host machine
|
# Used for allowing connections to homeservers hosted on the host machine
|
||||||
|
@ -48,4 +50,3 @@ services:
|
||||||
# Defaults to 127.0.0.1 and is set in docker/.env
|
# Defaults to 127.0.0.1 and is set in docker/.env
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "localhost:${HOST_IP_ADDRESS}"
|
- "localhost:${HOST_IP_ADDRESS}"
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
|
|
||||||
import prometheus_client
|
import prometheus_client
|
||||||
from aiohttp import ClientError, web, web_request
|
from aiohttp import ClientError, web, web_request
|
||||||
|
from aiohttp.abc import AbstractAccessLogger
|
||||||
from aiohttp_prometheus_exporter.handler import metrics
|
from aiohttp_prometheus_exporter.handler import metrics
|
||||||
from aiohttp_prometheus_exporter.middleware import prometheus_middleware_factory
|
from aiohttp_prometheus_exporter.middleware import prometheus_middleware_factory
|
||||||
from diskcache import Cache
|
from diskcache import Cache
|
||||||
|
@ -24,6 +25,38 @@ logger = logging.getLogger(__name__)
|
||||||
routes = web.RouteTableDef()
|
routes = web.RouteTableDef()
|
||||||
|
|
||||||
|
|
||||||
|
class AccessLogger(AbstractAccessLogger):
|
||||||
|
def log(
|
||||||
|
self,
|
||||||
|
request: web_request.BaseRequest,
|
||||||
|
response: web.StreamResponse,
|
||||||
|
time: float,
|
||||||
|
) -> None:
|
||||||
|
if request is None:
|
||||||
|
remote_address = "-"
|
||||||
|
request_info = "-"
|
||||||
|
referer_header = "-"
|
||||||
|
user_agent_header = "-"
|
||||||
|
else:
|
||||||
|
if request.remote is None:
|
||||||
|
remote_address = "-"
|
||||||
|
else:
|
||||||
|
remote_address = request.remote
|
||||||
|
|
||||||
|
request_info = (
|
||||||
|
f"{request.method} {request.path_qs} "
|
||||||
|
f"HTTP/{request.version.major}.{request.version.minor}"
|
||||||
|
)
|
||||||
|
|
||||||
|
referer_header = request.headers.get("Referer", "-")
|
||||||
|
user_agent_header = request.headers.get("User-Agent", "-")
|
||||||
|
|
||||||
|
self.logger.debug(
|
||||||
|
f'{remote_address} "{request_info}" {response.status} '
|
||||||
|
f'{response.body_length} "{referer_header}" "{user_agent_header}"'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@routes.get("/health")
|
@routes.get("/health")
|
||||||
async def get_health(request: web_request.Request) -> web.Response:
|
async def get_health(request: web_request.Request) -> web.Response:
|
||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
|
@ -153,7 +186,7 @@ class Webhook:
|
||||||
)
|
)
|
||||||
self.app.router.add_get("/metrics", metrics())
|
self.app.router.add_get("/metrics", metrics())
|
||||||
|
|
||||||
self.runner = web.AppRunner(self.app)
|
self.runner = web.AppRunner(self.app, access_log_class=AccessLogger)
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.address = config.address
|
self.address = config.address
|
||||||
|
|
Loading…
Reference in a new issue