Docker App: Diagnostics Logs Link Disabled

Category: azure functions

Question

shirisht on Tue, 09 Oct 2018 07:38:24


Hello,

I have created a Azure Function App that is published as a Docker Container (i.e, OS=Linux, Publish='Docker Image'), where corresponding the docker image is hosted on Azure Container Registry.

I have been trying to find a place to view the log messages generated from functions within the app. I noticed that "Diagnostics logs" link in my applications settings is disabled. Also in the log files from /home/LogFiles/ on kudu (<app_name>.scm.azurewebsites.net/), I see messages such as:

2018-10-09 05:14:50.993 INFO - Logging is not enabled for this container. Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.

Can anyone advise me on how do I enable logging for the app so that log messages generated from my functions (running within the container) can be found?

Thank you.


Replies

AhmedElSayed on Tue, 09 Oct 2018 22:25:14


If you follow that link you'll be able to see the stdout logs from your container.

If you're looking for functions specific logs, i.e: logs written to ILogger in your function or events from your function, you should check Application Insights (see this for details)

If you're looking for file logging from your function app, enable file logging in your host.json, then the logs should be present at /home/LogFiles/Application/Functions/

shirisht on Wed, 10 Oct 2018 19:18:08


Thank you @AhmedElSayed. Can you tell me how do I enable file logging in host.json? 

The code I have in my python function code is the following: 

logging.basicConfig(filename='/home/LogFiles/mylog2.txt',format='%(asctime)s %(levelname)s: %(message)s',level=logging.DEBUG)

logging.info("...")

I tried setting WEBSITES_ENABLE_APP_SERVICE_STORAGE=true hoping that I will be able to see `mylog2.txt` in the kudu container but failed the whole application. I saw from your previous posts (such as https://github.com/Azure/azure-functions-host/issues/2631) that we SHOULD NOT enable this flag. 

I hope enabling file logging in host.json will do the trick. Is that right? Can you please advise how to do it?

shirisht on Wed, 10 Oct 2018 19:20:32


I should have been more clear. I see a related setting here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#logging

but I am wondering how I can specify the file name. Otherwise, which file would contain the logs?