Skip to content

Commit 22888b3

Browse files
committed
Logging: suppress dependency loggers
1 parent 66677bf commit 22888b3

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

dp3/api/internal/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
from dp3.api.internal.dp_logger import DPLogger
1212
from dp3.common.config import ModelSpec, read_config_dir
13+
from dp3.common.utils import suppress_dependency_loggers
1314
from dp3.database.database import EntityDatabase
1415
from dp3.history_management.telemetry import TelemetryReader
1516
from dp3.task_processing.task_queue import TaskQueueWriter
1617

1718
DATAPOINTS_INGESTION_URL_PATH = "/datapoints"
1819

20+
suppress_dependency_loggers()
21+
1922

2023
class ConfigEnv(BaseModel):
2124
"""Configuration environment variables container"""

dp3/bin/schema_update.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88

99
from dp3.common.config import ModelSpec, read_config_dir
10+
from dp3.common.utils import suppress_dependency_loggers
1011
from dp3.database.database import EntityDatabase
1112

1213

@@ -41,6 +42,7 @@ def main(args):
4142
LOGFORMAT = "%(asctime)-15s,%(name)s,[%(levelname)s] %(message)s"
4243
LOGDATEFORMAT = "%Y-%m-%dT%H:%M:%S"
4344
logging.basicConfig(level=logging.DEBUG, format=LOGFORMAT, datefmt=LOGDATEFORMAT)
45+
suppress_dependency_loggers()
4446
log = logging.getLogger("SchemaUpdate")
4547

4648
# Connect to database

dp3/common/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
auxiliary/utility functions and classes
33
"""
44

5+
import logging
56
import re
67
from collections.abc import Iterable, Iterator
78
from datetime import datetime, timedelta
@@ -185,3 +186,17 @@ def get_func_name(func_or_method):
185186
except AttributeError:
186187
return fname
187188
return wrapper.format(name=f"{module}.{fname}", args=args)
189+
190+
191+
DEPENDENCY_LOGGERS = (
192+
"requests",
193+
"urllib3",
194+
"amqpstorm",
195+
"pymongo",
196+
)
197+
198+
199+
def suppress_dependency_loggers(level: int = logging.WARNING) -> None:
200+
"""Keep noisy third-party loggers quiet when DP3 enables verbose logging."""
201+
for logger_name in DEPENDENCY_LOGGERS:
202+
logging.getLogger(logger_name).setLevel(level)

dp3/worker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from dp3.common.callback_registrar import CallbackRegistrar, reload_module_config
1919
from dp3.common.config import PlatformConfig
2020
from dp3.common.control import Control, ControlAction, refresh_on_entity_creation
21+
from dp3.common.utils import suppress_dependency_loggers
2122
from dp3.core.collector import GarbageCollector
2223
from dp3.core.link_manager import LinkManager
2324
from dp3.core.updater import Updater
@@ -122,10 +123,7 @@ def main(app_name: str, config_dir: str, process_index: int, verbose: bool) -> N
122123
)
123124
log = logging.getLogger()
124125

125-
# Disable INFO and DEBUG messages from some libraries
126-
logging.getLogger("requests").setLevel(logging.WARNING)
127-
logging.getLogger("urllib3").setLevel(logging.WARNING)
128-
logging.getLogger("amqpstorm").setLevel(logging.WARNING)
126+
suppress_dependency_loggers()
129127

130128
##############################################
131129
# Load configuration

0 commit comments

Comments
 (0)