mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-17 18:44:11 -05:00
keep landing page independent from api
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from flask import (
|
||||
abort,
|
||||
current_app,
|
||||
@@ -19,6 +21,8 @@ from app.main.views.sub_navigation_dictionaries import (
|
||||
)
|
||||
from app.utils.user import user_is_logged_in
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Hook to check for feature flags
|
||||
@main.before_request
|
||||
@@ -42,10 +46,15 @@ def index():
|
||||
if current_user and current_user.is_authenticated:
|
||||
return redirect(url_for("main.choose_account"))
|
||||
|
||||
try:
|
||||
counts = status_api_client.get_count_of_live_services_and_organizations()
|
||||
except Exception as e:
|
||||
logger.warning(f"API down when loading homepage: {e}")
|
||||
counts = {"live_service_count": "N/A", "live_organization_count": "N/A"}
|
||||
return render_template(
|
||||
"views/signedout.html",
|
||||
sms_rate=CURRENT_SMS_RATE,
|
||||
counts=status_api_client.get_count_of_live_services_and_organizations(),
|
||||
counts=counts,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import logging
|
||||
import logging.handlers
|
||||
import re
|
||||
import sys
|
||||
from itertools import product
|
||||
@@ -10,6 +9,21 @@ from flask.ctx import has_app_context, has_request_context
|
||||
from flask.logging import default_handler
|
||||
from pythonjsonlogger.jsonlogger import JsonFormatter as BaseJSONFormatter
|
||||
|
||||
|
||||
class ColorFormatter(logging.Formatter):
|
||||
COLOR_MAP = {
|
||||
'DEBUG': '\033[94m',
|
||||
'WARNING': '\033[93m',
|
||||
'ERROR': '\033[91m',
|
||||
}
|
||||
RESET = '\033[0m'
|
||||
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
color = self.COLOR_MAP.get(record.levelname, self.RESET)
|
||||
base_message = super().format(record)
|
||||
return f"{color}{base_message}{self.RESET}"
|
||||
|
||||
|
||||
LOG_FORMAT = (
|
||||
"%(asctime)s %(app_name)s %(name)s %(levelname)s "
|
||||
'%(request_id)s %(service_id)s "%(message)s" [in %(pathname)s:%(lineno)d]'
|
||||
@@ -79,7 +93,7 @@ def init_app(app):
|
||||
|
||||
def get_handlers(app):
|
||||
handlers = []
|
||||
standard_formatter = logging.Formatter(LOG_FORMAT, TIME_FORMAT)
|
||||
color_formatter = ColorFormatter(LOG_FORMAT, TIME_FORMAT)
|
||||
json_formatter = JSONFormatter(LOG_FORMAT, TIME_FORMAT)
|
||||
|
||||
stream_handler = logging.StreamHandler(sys.stdout)
|
||||
@@ -92,9 +106,7 @@ def get_handlers(app):
|
||||
return not ("GET /static/" in msg and " 200 " in msg)
|
||||
|
||||
logging.getLogger("werkzeug").addFilter(is_200_static_log)
|
||||
|
||||
# human readable stdout logs
|
||||
handlers.append(configure_handler(stream_handler, app, standard_formatter))
|
||||
handlers.append(configure_handler(stream_handler, app, color_formatter))
|
||||
|
||||
return handlers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user