diff --git a/SPRINTLOG.md b/SPRINTLOG.md index bdf60e3b7..64dd873a9 100644 --- a/SPRINTLOG.md +++ b/SPRINTLOG.md @@ -461,4 +461,5 @@ _Nothing merged during this sprint_ # 2024-12-02 - 2024-12-13 -- Bugfix: Quick and dirty change to prevent `dds ls --tree` from failing systematically ([#1575](https://github.com/ScilifelabDataCentre/dds_web/pull/1575). +- Filter out the MaintenanceModeException from the logs ([#1573](https://github.com/ScilifelabDataCentre/dds_web/pull/1573)) +- Bugfix: Quick and dirty change to prevent `dds ls --tree` from failing systematically ([#1575](https://github.com/ScilifelabDataCentre/dds_web/pull/1575) diff --git a/dds_web/__init__.py b/dds_web/__init__.py index fd87c63ca..55d7e51cb 100644 --- a/dds_web/__init__.py +++ b/dds_web/__init__.py @@ -68,6 +68,20 @@ #################################################################################################### +class FilterMaintenanceExc(logging.Filter): + + 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""" @@ -164,6 +178,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: