ignoring cosmosdb info logs while developping Azure functions in python

Viewed 33

I'm developping Azure functions locally on vscode and I query a distant cosmosdb using the azure.cosmos module.

My problem is that each query to the cosmosdb produces logs of info (or verbose) logs in my terminal and makes reading my own logging.info() outputs quite hard to read.

logs I want to hide:

[2022-08-31T08:50:00.643Z] Request URL: 'https://xxx-norwayeast.documents.azure.com:443/dbs'
Request method: 'POST'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': 'REDACTED'
    'x-ms-documentdb-query-iscontinuationexpected': 'REDACTED'
    'x-ms-consistency-level': 'REDACTED'
    'x-ms-date': 'REDACTED'
    'authorization': 'REDACTED'
    'Content-Type': 'application/json'
    'Accept': 'application/json'
    'Content-Length': '12'
    'User-Agent': 'azsdk-python-cosmos/4.2.0 Python/3.9.12 (Windows-10-10.0.25188-SP0)'
A body is sent with the request

I do not know how to set the log level to ignore the cosmosdb logs (ideally only getting the warning/error logs) or to only print my own logs when I need to.

my host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "durableTask": {
      "hubName": "%TaskHub%"
    }
  }
}

my function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "context",
      "type": "orchestrationTrigger",
      "direction": "in"
    }
  ]
}
1 Answers

This needs to be a setting on the Azure Function, you can do that using the host.json

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "Function.YourFunctionName.User": "Information",
      "Function": "Error"
    }
  }
}
Related