0

I feel like it must be possible, but I've yet to find an answer.

I navigate here inside of my Function App:

enter image description here

Then click the drop down arrow and select Application Insight Logs

enter image description here

As you can see in that picture, there's a log with an [Information] tag. I thought maybe I could do something like this in my Azure Function that's running my python script:

import logging
logging.info("Hello?")

However, I'm not able to get messages to show up in those logs. How do I actually achieve this? If there's a different place where logs created with logging.info() show up, I'd love to know that as well.

host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "logLevel": {
    "default": "Information",
    "Host.Results": "Information",
    "Function": "Information",
    "Host.Aggregator": "Information"
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "queues": {
      "batchSize": 2,
      "maxDequeueCount": 2
    }
  },
  "functionTimeout": "00:45:00"
}
BlakeB9
  • 345
  • 1
  • 3
  • 13

1 Answers1

1

I believe, there is no different place to write log info, but we need to change the log levels accordingly in host.json for getting different types of logs.

I tried to log the information level logs in this workaround.

  1. In VS Code, Created Azure Functions - Python Stack.
  2. Added this code logging.info(f" Calling Activity Function") in Activity Function Code like below:

enter image description here

This is the host.json code by default:

"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
        }
    }
}

After running this durable function, it is logging the information level:

enter image description here

Please refer to this workaround where I had given information about logging levels and also optimization of application insights logs on Azure Python Function.

Updated Answer:

enter image description here

  • Gave your workaround a look and wanted to try adding the ```loglevel``` section to my json file. Although when I edit my json to that, it's telling me ```Property loglevel is not allowed``` – BlakeB9 May 13 '22 at 16:37
  • I will update my post with my host.json file – BlakeB9 May 13 '22 at 16:38
  • I guess you're able to get those messages to come out in the terminal when running the function locally, I guess my question was, how could I get those logs to show up in the cloud through the "Application Insights Logs"? It seems like I need to do something different in order for those logs to show up there. – BlakeB9 May 13 '22 at 16:43
  • Got It! I'll update the answer regarding how to get those in App Insights Logs (Azure Portal). –  May 14 '22 at 01:16
  • Thank you, are you also able to achieve this using ```logging.info()```? I'd probably rather not want to use ```logging.error()``` if I can avoid it. – BlakeB9 May 16 '22 at 19:39
  • Yes @BlakeB9, I'm able to achieve using `logging.info()`. –  May 17 '22 at 02:25