Log routing in Azure functions

ZZ 120 Reputation points
2025-01-16T13:55:12.0566667+00:00

My function is built in Python and is built on the following scenario:

  • it uses logging
  • it downloads something from a blob container
  • it uses a library I built myself, let's say it is called 'mylib'. mylib uses logging, and makes openai RESTful calls

Here is a very simple example code:

Function A

import logging
from mylib import mytest

logging.getLogger('azure.stora  # Specific to Blob Storage SDK
logging.getLogger('requests').setLevel(logging.WARNING)

def main():
  	logging.info("Downloading from blob...") #LINE A
  
	connection_string = os.getenv('AzureWebJobsStorage')
	blob_service_client = BlobServiceClient.from_connection_string(connection_string)
	blob_container_client = blob_service_client.get_container_client('name')
	blobs = blob_container_client.list_blobs(name_starts_with=folder_name)
	for blob in blobs:
		#code to download
		....

	logging.info("Download completed, calling mylib functions") #LINE B
	mytest.do_something()
	logging.info("Task done") #LINE B

mylib.mytest


import logging

def mytest():
	logging.info("Making a call to openai")
	# code to call openai api
	logging.info("Call completed")

What is the problem

  1. When viewing the logs produced my function_A in azure, I only see the three lines of logs produced by function_A.py, i.e., line A, B, C above
  2. Logs produced by mylib.mytest is routed to a log file sitting in 'File Shares > function_A9ecd > LogFiles > Application > Functions > Host > xxxxx.log'. This log files have ALL logs produced including lines A, B, C from function_A.py, logs from mylib.mytest, and also many many other things like http calls, downloading from the blob, etc

For example, in 2, I see lots of lines like:

[2025-01-16T13:24:21.918Z] No body was attached to the request
[2025-01-16T13:24:21.997Z] Response status: 206
[2025-01-16T13:24:21.997Z] Response headers:
[2025-01-16T13:24:21.997Z]     'Content-Length': '4194304'
[2025-01-16T13:24:21.997Z]     'Content-Type': 'application/zip'
[2025-01-16T13:24:21.997Z]     'Content-Range': 'REDACTED'
[2025-01-16T13:24:21.997Z]     'Last-Modified': 'Thu, 16 Jan 2025 12:44:48 GMT'
[2025-01-16T13:24:21.997Z]     'Accept-Ranges': 'REDACTED'
[2025-01-16T13:24:21.997Z]     'ETag': '"0x8DD362B8FE36B02"'
[2025-01-16T13:24:21.997Z]     'Server': 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0'
[2025-01-16T13:24:21.997Z]     'x-ms-request-id': 'e1d0f338-001e-0018-4119-685f49000000'
[2025-01-16T13:24:21.997Z]     'x-ms-client-request-id': '31f0f449-d40d-11ef-98f4-b7664ff83e71'
[2025-01-16T13:24:21.997Z]     'x-ms-version': 'REDACTED'
[2025-01-16T13:24:21.997Z]     'x-ms-creation-time': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'x-ms-blob-content-md5': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'x-ms-lease-status': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'x-ms-lease-state': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'x-ms-blob-type': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'x-ms-server-encrypted': 'REDACTED'
[2025-01-16T13:24:21.998Z]     'Date': 'Thu, 16 Jan 2025 13:24:21 GMT'
[2025-01-16T13:24:22.915Z] Request URL: ''

And

[2025-01-16T13:33:10.010Z] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"

My questions are

  1. Is there a way to route logs produced by mylib.mytest to the logs of function A? I currently assume 'no' having read this https://stackoverflow.com/questions/78672450/fastapi-logging-in-routes-in-azure-functions
  2. Is there a way to block logs produced by URL request and open AI calls, like those two shown at the end above? You may have noticed the two lines I added to my function but they don't work:
logging.getLogger('azure.storage.blob').setLevel(logging.WARNING)  # Specific to Blob Storage SDK
logging.getLogger('requests').setLevel(logging.WARNING)
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 17,766 Reputation points Moderator
    2025-01-16T19:15:32.44+00:00

    Hi @ZZ Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I am not sure if the first option of sending logs from mylib.mytest to appear in the logs of function A is possible.

    For setting log level at the function, in addition to adding the above mentioned statements, you can adjust the same by modifying the log level in host.json file. Please find more details in the documentation Control volume and verbosity of logs Here is a sample setting

    {
      "version": "2.0",
      "logging": {
        "logLevel": {
          "default": "Information", // catch all default, with modifications below for individual categories.
          "Function": "Warning", // Warning level from all Functions (except the ones configured below).
          "Host.Aggregator": "Trace", // Log all traces in the 'customMetrics' table of (and shown on Metrics/Alerts blade in AI) - use either this or Host.Results
          "Host.Results": "Error", // Error and Critical requests are only logged in the 'requests' table of the AI (and shown on Monitor Functions blade in Functions App) - use either this or Host.Aggregator
          "Function.Function1": "Information", //Information level logs from Function 1, logged in 'traces', 'dependencies' and 'customMetrics' tables of AI
          "Function.Function2.User": "Information" //user code logs from Function2, logged in 'traces' table of AI
        },
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "maxTelemetryItemsPerSecond": 1,
            "excludedTypes": "Exception"
          }
        }
      }
    }
    

    Hope this helps! Please let us know if you have additional questions or need further assistance.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.