I'm trying to log info to Application Insights at the module level of code as oppsosed to the function level.
I can successfully log INFO, WARNING etc when the logger is called from within a function (in any module of my project), but not when called outside a function, (eg initializing a module, want to log some settings)
For example, when running my HttpTrigger app in azure functions, this works, and logs info to app insights:
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('this message is logged successfully')
do_something()
while this does not work:
import logging
logging.info('this message isnt logged anywhere')
def main(req: func.HttpRequest) -> func.HttpResponse:
do_something()
I've tried using named loggers, changing logging settings eg:
import logging
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
log.info('This still isnt logged')
def main(req: func.HttpRequest) -> func.HttpResponse:
do_something()
and changing config in host.json:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Information",
"Host.Results": "Information",
"Function": "Information",
"Host.Aggregator": "Information"
}
}
}
When running code locally, info is printed to stdout correctly everywhere.
I assume I must be misunderstanding exactlty how logging works in az. If anyone can fill in my gaps here for why the logging isn't working as I expect that would be appreciated!



