Skip to content

Commit a7a6049

Browse files
introduce logger filtering
1 parent 62361d9 commit a7a6049

File tree

35 files changed

+136
-29
lines changed

35 files changed

+136
-29
lines changed

.env-devel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ INVITATIONS_SWAGGER_API_DOC_ENABLED=1
124124
INVITATIONS_USERNAME=admin
125125

126126
LOG_FORMAT_LOCAL_DEV_ENABLED=1
127+
LOG_FILTER_MAPPING='{}'
127128

128129
PAYMENTS_ACCESS_TOKEN_EXPIRE_MINUTES=30
129130
PAYMENTS_ACCESS_TOKEN_SECRET_KEY=2c0411810565e063309be1457009fb39ce023946f6a354e6935107b57676

packages/service-library/src/servicelib/logging_utils.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def format(self, record) -> str:
8686
# log_level=%{WORD:log_level} \| log_timestamp=%{TIMESTAMP_ISO8601:log_timestamp} \| log_source=%{DATA:log_source} \| log_msg=%{GREEDYDATA:log_msg}
8787

8888

89-
def config_all_loggers(*, log_format_local_dev_enabled: bool) -> None:
89+
def config_all_loggers(
90+
*, log_format_local_dev_enabled: bool, logger_filter_mapping: dict[str, list[str]]
91+
) -> None:
9092
"""
9193
Applies common configuration to ALL registered loggers
9294
"""
@@ -106,18 +108,7 @@ def config_all_loggers(*, log_format_local_dev_enabled: bool) -> None:
106108
logger, fmt=fmt, log_format_local_dev_enabled=log_format_local_dev_enabled
107109
)
108110

109-
LOGGER_FILTER_MAPPING = {
110-
"uvicorn.access": [
111-
'"GET / HTTP/1.1" 200',
112-
'"GET /metrics HTTP/1.1" 200',
113-
],
114-
"gunicorn.access": [
115-
'"GET /v0/ HTTP/1.1" 200',
116-
'"GET /v0/health HTTP/1.1" 200',
117-
],
118-
}
119-
logger_mapping = LOGGER_FILTER_MAPPING
120-
for logger_name, filtered_routes in logger_mapping.items():
111+
for logger_name, filtered_routes in logger_filter_mapping.items():
121112
logger = logging.getLogger(logger_name)
122113
# Check if the logger has any handlers or is in active use
123114
if not logger.hasHandlers():

services/agent/src/simcore_service_agent/core/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def _setup_logger(settings: ApplicationSettings):
3030
logging.basicConfig(level=settings.LOGLEVEL.value) # NOSONAR
3131
logging.root.setLevel(settings.LOGLEVEL.value)
3232
config_all_loggers(
33-
log_format_local_dev_enabled=settings.AGENT_VOLUMES_LOG_FORMAT_LOCAL_DEV_ENABLED
33+
log_format_local_dev_enabled=settings.AGENT_VOLUMES_LOG_FORMAT_LOCAL_DEV_ENABLED,
34+
logger_filter_mapping={},
3435
)
3536

3637

services/agent/src/simcore_service_agent/core/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
2525
"disabled if you want to have structured logs!"
2626
),
2727
)
28+
AGENT_VOLUMES_LOG_FILTER_MAPPING: dict = Field(
29+
default={},
30+
env=["AGENT_VOLUMES_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"],
31+
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
32+
)
2833
AGENT_VOLUMES_CLEANUP_TARGET_SWARM_STACK_NAME: str = Field(
2934
..., description="Exactly the same as director-v2's `SWARM_STACK_NAME` env var"
3035
)

services/api-server/src/simcore_service_api_server/core/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def init_app(settings: ApplicationSettings | None = None) -> FastAPI:
5252
logging.basicConfig(level=settings.log_level)
5353
logging.root.setLevel(settings.log_level)
5454
config_all_loggers(
55-
log_format_local_dev_enabled=settings.API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED
55+
log_format_local_dev_enabled=settings.API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED,
56+
logger_filter_mapping={},
5657
)
5758
_logger.debug("App settings:\n%s", settings.json(indent=2))
5859

services/api-server/src/simcore_service_api_server/core/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class BasicSettings(BaseCustomSettings, MixinLoggingSettings):
5555
env=["API_SERVER_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"],
5656
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
5757
)
58+
API_SERVER_LOG_FILTER_MAPPING: dict = Field(
59+
default={},
60+
env=["API_SERVER_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"],
61+
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
62+
)
5863

5964
@validator("LOG_LEVEL", pre=True)
6065
@classmethod

services/autoscaling/src/simcore_service_autoscaling/core/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
240240
],
241241
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
242242
)
243+
AUTOSCALING_LOG_FILTER_MAPPING: dict = Field(
244+
default={},
245+
env=["AUTOSCALING_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"],
246+
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
247+
)
243248

244249
AUTOSCALING_EC2_ACCESS: AutoscalingEC2Settings | None = Field(
245250
auto_default_from_env=True

services/autoscaling/src/simcore_service_autoscaling/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
logging.basicConfig(level=the_settings.log_level)
1414
logging.root.setLevel(the_settings.log_level)
1515
config_all_loggers(
16-
log_format_local_dev_enabled=the_settings.AUTOSCALING_LOG_FORMAT_LOCAL_DEV_ENABLED
16+
log_format_local_dev_enabled=the_settings.AUTOSCALING_LOG_FORMAT_LOCAL_DEV_ENABLED,
17+
logger_filter_mapping={},
1718
)
1819

1920
# SINGLETON FastAPI app

services/catalog/src/simcore_service_catalog/core/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
6161
env=["CATALOG_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"],
6262
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
6363
)
64+
CATALOG_LOG_FILTER_MAPPING: dict = Field(
65+
default={},
66+
env=["CATALOG_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"],
67+
description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.",
68+
)
6469
CATALOG_DEV_FEATURES_ENABLED: bool = Field(
6570
default=False,
6671
description="Enables development features. WARNING: make sure it is disabled in production .env file!",

services/catalog/src/simcore_service_catalog/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
logging.basicConfig(level=_the_settings.CATALOG_LOG_LEVEL.value) # NOSONAR
1515
logging.root.setLevel(_the_settings.CATALOG_LOG_LEVEL.value)
1616
config_all_loggers(
17-
log_format_local_dev_enabled=_the_settings.CATALOG_LOG_FORMAT_LOCAL_DEV_ENABLED
17+
log_format_local_dev_enabled=_the_settings.CATALOG_LOG_FORMAT_LOCAL_DEV_ENABLED,
18+
logger_filter_mapping={},
1819
)
1920

2021

0 commit comments

Comments
 (0)