pythonazureazure-functions

How can I view error logs from a Python Azure Function App?


I'm working on some Python Function Apps using Linux and the consumption plan. I'm trying to figure out where I can see error logs from my apps without a lot of success. In particular I want to see two things:

Neither of these appear in any of the logging or insights screens I've been able to find. I've resorted to wrapping all my code in try/except blocks and returning the errors in my response but that's not great. I must be missing something obvious here!

Thanks for the help.


Solution

  • There are many ways you can monitor your Azure Functions Trigger, Refer below:-

    I deployed one HTTP trigger function on Azure Portal from my local machine and triggered it to get the logs like below:-

    Method 1) Go to your Azure Function app > Select your trigger > Code + Test > Test the Function and the Log stream will log all your Trigger's failure and success with error code, Refer below:-

    enter image description here

    And then you can change the logging type to either Verbose, Information, Warning, Error. If the above logs did not appear after you trigger your HTTP request or any function Trigger API, Just change the Logging to another type.

    enter image description here

    Method 2) Visit Monitor Section > and check for all the Trigger request invocations, warnings, errors like below:-

    enter image description here

    enter image description here

    You can click on run query in Application insights and query the logs:-

    enter image description here

    Logs:-

    enter image description here

    Method 3)

    You can visit your function app and select Logs tab and query Logs like below:-

    enter image description here

    You can visit Log Stream and find the same console Logs for your Function, This option is feasible when you have multiple Triggers inside one function app, Where it gives a single point to check the Function Trigger logs quickly:-

    enter image description here

    You can click on Metrics and get insights on your function's failed requests and other parameter like below:-

    enter image description here

    Refer my SO thread answer to send custom logs in Azure Function with Application Insights.

    You can also add specific logging parameters in your host.json as referred from this MS Document on configuring Azure Functions logging.

    
    {   "logger": {
        "categoryFilter": {
          "defaultLevel": "Information",
          "categoryLevels": {
            "Host": "Error",
            "Function": "Error",
            "Host.Aggregator": "Information"
          }
        }  
      }
    }
    
    

    App service Logs are disabled in Azure Function app with Consumption based plan, If you want to check App Service Logs and Advance tool kudu which also has details of your Function deployment and other Logs, You need to create your function app as Premium plan. Refer below:-

    Function app > Development Tools > Advance Tools > Kudu > Go

    enter image description here

    Enable App Service logs:-

    enter image description here

    Reference:-

    Monitoring Azure Functions | Microsoft Learn