From e2c85c2c77a402d89e667a386af48be4756ca2a3 Mon Sep 17 00:00:00 2001 From: jerevoss Date: Wed, 25 Jan 2023 14:01:54 -0800 Subject: [PATCH] Disabling diagnostics for diagnostic module. Added duplicate handler test --- CHANGELOG.md | 2 ++ .../distro/_diagnostics/_diagnostic_logging.py | 2 -- .../tests/diagnostics/test_diagnostic_logging.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c62bb239..14a8a961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ ([#218](https://github.com/microsoft/ApplicationInsights-Python/pull/218)) - Add instrumentation selection config ([#228](https://github.com/microsoft/ApplicationInsights-Python/pull/228)) +- Removing diagnostic logging from its module's logger. + ([#225](https://github.com/microsoft/ApplicationInsights-Python/pull/225)) ## [1.0.0b8](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b8) - 2022-09-26 diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_diagnostic_logging.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_diagnostic_logging.py index e0f3ad4c..e28826fe 100644 --- a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_diagnostic_logging.py +++ b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_diagnostics/_diagnostic_logging.py @@ -18,7 +18,6 @@ ) from azure.monitor.opentelemetry.distro._version import VERSION -_OPENTELEMETRY_DIAGNOSTIC_LOGGER_NAME = "opentelemetry" _DIAGNOSTIC_LOGGER_FILE_NAME = "applicationinsights-extension.log" _SITE_NAME = _env_var_or_default("WEBSITE_SITE_NAME") _SUBSCRIPTION_ID_ENV_VAR = _env_var_or_default("WEBSITE_OWNER_NAME") @@ -68,7 +67,6 @@ def _initialize(): fmt=format, datefmt="%Y-%m-%dT%H:%M:%S" ) AzureDiagnosticLogging._f_handler.setFormatter(formatter) - _logger.addHandler(AzureDiagnosticLogging._f_handler) AzureDiagnosticLogging._initialized = True _logger.info("Initialized Azure Diagnostic Logger.") diff --git a/azure-monitor-opentelemetry-distro/tests/diagnostics/test_diagnostic_logging.py b/azure-monitor-opentelemetry-distro/tests/diagnostics/test_diagnostic_logging.py index d231d07c..6f874566 100644 --- a/azure-monitor-opentelemetry-distro/tests/diagnostics/test_diagnostic_logging.py +++ b/azure-monitor-opentelemetry-distro/tests/diagnostics/test_diagnostic_logging.py @@ -151,6 +151,14 @@ def test_warning(self): TEST_LOGGER_SUB_MODULE.warning(MESSAGE2) check_file_for_messages("WARNING", (MESSAGE1, MESSAGE2)) + def test_warning_multiple_enable(self): + set_up(is_diagnostics_enabled=True) + diagnostic_logger.AzureDiagnosticLogging.enable(TEST_LOGGER) + diagnostic_logger.AzureDiagnosticLogging.enable(TEST_LOGGER) + TEST_LOGGER_SUB_MODULE.warning(MESSAGE1) + TEST_LOGGER_SUB_MODULE.warning(MESSAGE2) + check_file_for_messages("WARNING", (MESSAGE1, MESSAGE2)) + def test_error(self): set_up(is_diagnostics_enabled=True) TEST_LOGGER_SUB_MODULE.error(MESSAGE1)