Skip to content

Commit 42f74c8

Browse files
Only enable logger when environment variable is set
1 parent 3a433bf commit 42f74c8

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

datareservoirio/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import time
34
import warnings
45
from collections import defaultdict
@@ -22,6 +23,8 @@
2223
)
2324
from tqdm.auto import tqdm
2425

26+
from datareservoirio._constants import ENV_VAR_ENABLE_APP_INSIGHTS
27+
2528
from ._logging import log_decorator
2629
from ._utils import function_translation, period_translation
2730
from .globalsettings import environment
@@ -33,11 +36,14 @@
3336
@cache
3437
def metric() -> logging.Logger:
3538
logger = logging.getLogger(__name__ + "_metric_appinsight")
36-
logger.setLevel(logging.DEBUG)
37-
configure_azure_monitor(
38-
connection_string=environment._application_insight_connectionstring,
39-
logger_name=__name__ + "_metric_appinsight",
40-
)
39+
if os.getenv(ENV_VAR_ENABLE_APP_INSIGHTS) is not None:
40+
enable_app_insights = os.environ[ENV_VAR_ENABLE_APP_INSIGHTS].lower()
41+
if enable_app_insights == "true" or enable_app_insights == "1":
42+
logger.setLevel(logging.DEBUG)
43+
configure_azure_monitor(
44+
connection_string=environment._application_insight_connectionstring,
45+
logger_name=__name__ + "_metric_appinsight",
46+
)
4147
return logger
4248

4349

tests/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
from io import BytesIO
32
from pathlib import Path
43
from unittest.mock import Mock
@@ -13,14 +12,6 @@
1312
TEST_PATH = Path(__file__).parent
1413

1514

16-
@pytest.fixture(autouse=True)
17-
def disable_logging(monkeypatch):
18-
"""Disable logging to Application Insight"""
19-
20-
21-
# monkeypatch.setattr("datareservoirio.client.AzureLogHandler", logging.NullHandler())
22-
23-
2415
@pytest.fixture
2516
def response_cases():
2617
class ResponseCaseHandler:

0 commit comments

Comments
 (0)