if I run locally, I can see my print()
texts. But even after enable File System App Service Logs, I still don't see any logs, both in _docker.log
or streaming log. What is the right way to generate local logs for Python on Azure App Service?
To close the loop, I ended up making a simple log method
def writeLog(log: str):
basepath = path.dirname(__file__)
today = date.today()
filepath = path.abspath(path.join(basepath, "..", "..", "LogFiles", "MyBot_" + today.strftime("%Y-%m-%d") + ".log"))
f = open(filepath, "a+")
f.write(today.strftime("%Y-%m-%d %H:%M:%S") + " " + log)
f.write("\n")
f.close()
If I don't close()
, I won't be able to download the file. Putting it in LogFiles
together with other log files makes it easier to view from VS Code
I test with a Flask web and set the WSGI_LOG follow this doc: Configure the FastCGI handler , it will create the log however the logs file only have the StdErr
log, about StdOut
it's always blank.
So I use another solution to redirect the standard output of your scripts to some log file.
import sys
sys.stdout = open('D:\\home\\LogFiles\\app.log', 'w')
print("test")
You can configure the above code, then publish your code and run it.
I was encountering a similar issue. In my case the logging was inconsistent in relation to the other logs in the container. In the end it seemed to be more of a log buffering issue, rather than something specific to Azure App Service. It was solved by setting the following environment variable in Azure App Service: Settings -> Container -> Application Settings
PYTHONUNBUFFERED = 1
In a docker run command you'd set it as:
--env PYTHONUNBUFFERED=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.