Skip to content

Commit bd598ad

Browse files
authored
Allow the setting of log level by env vars (#642)
* Allow the setting of log level by env vars Required by #637 * Allow the setting of log level by env vars Required by #637 * Add loglevel to env.sample * Allow log level to be set via bicep * Set log level in admin app * Correctly configure logs in web app * Ensure log level is set for functions * Remove duplicated tests * Fix main.json after merge * Reduce verbose azure logs
1 parent 2b63ecf commit bd598ad

17 files changed

+89
-26
lines changed

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ AZURE_SPEECH_SERVICE_REGION=
5555
AZURE_AUTH_TYPE=keys
5656
USE_KEY_VAULT=true
5757
AZURE_KEY_VAULT_ENDPOINT=
58+
LOGLEVEL=INFO

code/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import os
2+
import logging
23
from azure.monitor.opentelemetry import configure_azure_monitor
34
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
45

6+
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO").upper())
7+
# Raising the azure log level to WARN as it is too verbose - https://github.com/Azure/azure-sdk-for-python/issues/9422
8+
logging.getLogger("azure").setLevel(os.environ.get("LOGLEVEL_AZURE", "WARN").upper())
59
# We cannot use EnvHelper here as Application Insights should be configured first
610
# for instrumentation to work correctly
711
if os.getenv("APPINSIGHTS_ENABLED", "false").lower() == "true":

code/backend/Admin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010

1111
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
1212

13+
logging.basicConfig(level=os.getenv("LOGLEVEL", "INFO").upper())
14+
# Raising the azure log level to WARN as it is too verbose - https://github.com/Azure/azure-sdk-for-python/issues/9422
15+
logging.getLogger("azure").setLevel(os.environ.get("LOGLEVEL_AZURE", "WARN").upper())
1316
# We cannot use EnvHelper here as Application Insights needs to be configured first
1417
# for instrumentation to work correctly
1518
if os.getenv("APPINSIGHTS_ENABLED", "false").lower() == "true":
1619
configure_azure_monitor()
1720

18-
logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
19-
logging.WARNING
20-
)
21+
logger = logging.getLogger(__name__)
22+
logger.debug("Starting admin app")
2123

2224

2325
st.set_page_config(

code/backend/batch/AddURLEmbeddings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import azure.functions as func
44
import sys
55

6+
from utilities.helpers.EnvHelper import EnvHelper
67
from utilities.helpers.DocumentProcessorHelper import DocumentProcessor
78
from utilities.helpers.ConfigHelper import ConfigHelper
89

910
sys.path.append("..")
1011

1112
bp_add_url_embeddings = func.Blueprint()
13+
env_helper: EnvHelper = EnvHelper()
1214

1315
logger = logging.getLogger(__name__)
16+
logger.setLevel(env_helper.LOGLEVEL)
1417

1518

1619
@bp_add_url_embeddings.route(route="AddURLEmbeddings")

code/backend/batch/BatchPushResults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
from urllib.parse import urlparse
55
import sys
66

7+
from utilities.helpers.EnvHelper import EnvHelper
78
from utilities.helpers.AzureBlobStorageHelper import AzureBlobStorageClient
89
from utilities.helpers.DocumentProcessorHelper import DocumentProcessor
910
from utilities.helpers.ConfigHelper import ConfigHelper
1011

1112
sys.path.append("..")
1213

1314
bp_batch_push_results = func.Blueprint()
15+
env_helper: EnvHelper = EnvHelper()
1416

1517
logger = logging.getLogger(__name__)
18+
logger.setLevel(env_helper.LOGLEVEL)
1619

1720

1821
def _get_file_name_from_message(msg: func.QueueMessage) -> str:

code/backend/batch/BatchStartProcessing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
env_helper: EnvHelper = EnvHelper()
1414

1515
logger = logging.getLogger(__name__)
16+
logger.setLevel(env_helper.LOGLEVEL)
1617

1718

1819
@bp_batch_start_processing.route(route="BatchStartProcessing")

code/backend/batch/GetConversationResponse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
env_helper: EnvHelper = EnvHelper()
1212

1313
logger = logging.getLogger(__name__)
14+
logger.setLevel(env_helper.LOGLEVEL)
1415

1516

1617
@bp_get_conversation_response.route(route="GetConversationResponse")

code/backend/batch/function_app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import logging
2+
import os
13
import azure.functions as func
24
from AddURLEmbeddings import bp_add_url_embeddings
35
from BatchPushResults import bp_batch_push_results
46
from BatchStartProcessing import bp_batch_start_processing
57
from GetConversationResponse import bp_get_conversation_response
68
from azure.monitor.opentelemetry import configure_azure_monitor
79

10+
# Raising the azure log level to WARN as it is too verbose - https://github.com/Azure/azure-sdk-for-python/issues/9422
11+
logging.getLogger("azure").setLevel(os.environ.get("LOGLEVEL_AZURE", "WARN").upper())
812
configure_azure_monitor()
913

1014
app = func.FunctionApp(

code/backend/batch/utilities/helpers/EnvHelper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def __init__(self, **kwargs) -> None:
1414
# Wrapper for Azure Key Vault
1515
self.secretHelper = SecretHelper()
1616

17+
self.LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper()
18+
1719
# Azure Search
1820
self.AZURE_SEARCH_SERVICE = os.getenv("AZURE_SEARCH_SERVICE", "")
1921
self.AZURE_SEARCH_INDEX = os.getenv("AZURE_SEARCH_INDEX", "")

code/backend/pages/01_Ingest_Data.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import traceback
66
import chardet
77
from datetime import datetime, timedelta
8-
import logging
98
import requests
109
from azure.identity import DefaultAzureCredential
1110
from azure.storage.blob import (
@@ -22,9 +21,6 @@
2221
sys.path.append(path.join(path.dirname(__file__), ".."))
2322
env_helper: EnvHelper = EnvHelper()
2423

25-
logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
26-
logging.WARNING
27-
)
2824
st.set_page_config(
2925
page_title="Ingest Data",
3026
page_icon=path.join("images", "favicon.ico"),

0 commit comments

Comments
 (0)