Why do logs for a timer-triggered Function not get included when downloading logs from CLI?

Dan Temple 40 Reputation points
2023-08-11T06:54:12.19+00:00

I am using the CLI command to download logs for a timer triggered Azure Function:

az webapp log download --name ClickupCalendarMaintenance --resource-group ClickupRESGroup

This successfully downloads a file webapp_logs.zip, but there are no logs under the LogFiles/ directory. At least, none with the normal content.

As part of the same FunctionApp, there is a HTTP triggered endpoint Function. This DOES have logs in the file when downloaded.

Using the 'tail' function for the timer triggered function just says "no new trace" every minute. Even though the function IS triggering, and indeed running, and logs are visible in the GUI.

Why would the logs for this function be visible in the GUI, but not through the API?

Logging config is the same for both the timer triggered and the HTTP triggered:

az webapp log show

{
  "applicationLogs": {
    "azureBlobStorage": {
      "level": "Off",
      "retentionInDays": null,
      "sasUrl": null
    },
    "azureTableStorage": {
      "level": "Off",
      "sasUrl": null
    },
    "fileSystem": {
      "level": "Error"
    }
  },
  "detailedErrorMessages": {
    "enabled": false
  },
  "failedRequestsTracing": {
    "enabled": false
  },
  "httpLogs": {
    "azureBlobStorage": {
      "enabled": false,
      "retentionInDays": null,
      "sasUrl": null
    },
    "fileSystem": {
      "enabled": false,
      "retentionInDays": null,
      "retentionInMb": 35
    }
  },
  "id": "/subscriptions/b1dfff06-9232-4c4d-ad46-1f480e660ce9/resourceGroups/ClickupRESGroup/providers/Microsoft.Web/sites/ClickupCalendarMaintenance/config/logs",
  "kind": null,
  "location": "West Europe",
  "name": "logs",
  "resourceGroup": "ClickupRESGroup",
  "type": "Microsoft.Web/sites/config"
}

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Brian Zarb 1,685 Reputation points
    2023-08-11T07:08:05.2733333+00:00

    Hi Dan,

    I think the issue resides in what you are trying to log. Your logging configuration for the file system is set to "Error" level. If your timer-triggered function is producing logs at a level other than "Error" (like "Information", "Verbose", or "Warning"), those logs won't be saved in the file system and subsequently won't be downloaded with the az webapp log download command.

    I recommend starting with the above as its the simplest way.


    Also, Sometimes, logs visible in the Azure portal (especially through the monitor blade) are stored in a different location than those accessed via the az webapp log download command. The command is designed to download logs from the file system, but the portal may also display logs stored in other services like Application Insights. Ensure that your function's logs aren't being stored or streamed to a different location.

    this is a bit complex to determine, however, here is how you can do it:

    Identify the Storage Location:

    • Open the Azure portal & Navigate to your Azure Function.
      • Under the Monitoring section, click on "Diagnostic settings" or "Diagnostic logs". This should show you where your logs are being sent to. Common destinations include Application Insights, Azure Blob Storage, Azure Monitor Logs, etc.

    Access Logs in Application Insights:

    • If your logs are stored in Application Insights:
    • Navigate to the Application Insights instance associated with your Function App.
    • Use the "Search" or "Logs" section to query and view your logs.
      • For programmatic access or for downloading the logs, you can use the Application Insights REST API.

    Access Logs in Azure Blob Storage:

    • If your logs are being sent to Azure Blob Storage:
      • Navigate to the Storage Account and find the Blob container where logs are stored.
        • Use Azure Storage Explorer, Azure portal, or Azure CLI to download the log blobs.
          • For instance, to download blobs using Azure CLI:
    az storage blob download --container-name your-container-name --name your-blob-name --file destination-file-path --account-name your-storage-account-name
    

    Azure Monitor Logs (Log Analytics):

    • If your logs are stored in Azure Monitor Logs:
    • Navigate to the Log Analytics workspace where your logs are stored.
    • Use the Kusto Query Language (KQL) to query your logs.
    • There is no direct Azure CLI command to download logs from Log Analytics as of my last update in September 2021. However, you can use the Azure REST API or PowerShell to programmatically retrieve logs.

    Adjust Diagnostic Settings:

    • If you wish for your logs to also be stored in the file system for easy access via az webapp log download:
      • Navigate to the Azure Function's Diagnostic settings.
        • Adjust the destination to include Filesystem, ensuring that the correct log level and category are set.

    More information: https://learn.microsoft.com/en-us/azure/azure-monitor/data-sources

    I hope this helps, if you where able to resolve your issue please mark this as your answer., and consider following.


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.