Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaintenanceOngoingException #1573

Merged
merged 12 commits into from
Dec 3, 2024
4 changes: 4 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,7 @@ _Nothing merged during this sprint_
- Workflow: Bump GitHub checkout action to v4 ([#1556](https://github.com/ScilifelabDataCentre/dds_web/pull/1556))
- Workflow: CodeQL action version(s) bumped to v3 ([#1569](https://github.com/ScilifelabDataCentre/dds_web/pull/1569))
- Workflow: Setup-node, codecov and upload-sarif action versions bumped to v4, v4 and v3, respectively ([#1570](https://github.com/ScilifelabDataCentre/dds_web/pull/1570))

# 2024-11-04 - 2024-11-15

- Filter out the MaintenanceModeException from the logs ([#1573](https://github.com/ScilifelabDataCentre/dds_web/pull/1573))
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions dds_web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from flask_httpauth import HTTPBasicAuth, HTTPTokenAuth
import flask_mail
import flask_login
from flask.logging import logging as flask_logging
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
import flask_migrate


Expand Down Expand Up @@ -68,6 +69,20 @@
####################################################################################################


class FilterMaintenanceExc(flask_logging.Filter):
rv0lt marked this conversation as resolved.
Show resolved Hide resolved

def filter(record):
"""
Filters log records to exclude those with MaintenanceOngoingException.
Returns:
bool: True if the log record should be logged, False if it should be filtered out.
"""
from dds_web.errors import MaintenanceOngoingException

# Check if the log record does not have an exception or if the exception is not MaintenanceOngoingException
return record.exc_info is None or record.exc_info[0] != MaintenanceOngoingException


def setup_logging(app):
"""Setup loggers"""

Expand Down Expand Up @@ -164,6 +179,9 @@ def action_wrapper(_, __, event_dict):
cache_logger_on_first_use=True,
)

# Add custom filter to the logger
logging.getLogger("general").addFilter(FilterMaintenanceExc)


def create_app(testing=False, database_uri=None):
try:
Expand Down