generated from Randers-Kommune-Digitalisering/python-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.py
28 lines (19 loc) · 958 Bytes
/
logging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
import logging
import re
from werkzeug import serving
from prometheus_client import Gauge
from utils.config import DEBUG
# Prometheus
APP_RUNNING = Gauge('up', '1 - app is running, 0 - app is down', labelnames=['name'])
# Logging configuration
def set_logging_configuration():
log_level = logging.DEBUG if DEBUG else logging.INFO
logging.basicConfig(stream=sys.stdout, level=log_level, format='[%(asctime)s] %(levelname)s - %(name)s - %(module)s:%(funcName)s - %(message)s', datefmt='%d-%m-%Y %H:%M:%S')
disable_endpoint_logs(('/metrics', '/healthz'))
def disable_endpoint_logs(disabled_endpoints):
parent_log_request = serving.WSGIRequestHandler.log_request
def log_request(self, *args, **kwargs):
if not any(re.match(f"{de}$", self.path) for de in disabled_endpoints):
parent_log_request(self, *args, **kwargs)
serving.WSGIRequestHandler.log_request = log_request