Reputation: 4142
I am new to Azure and I deployed a flask application to Azure. Just curious where Azure save the logs if I print (console log) something in the application. Just curious if there is any log folder by default or do I have to setup one of my own? If so, how can I create one?
Its creating the log file but it is not writing anything to it,
import sys
app = Flask(__name__)
sys.stdout = open('D:/home/LogFiles/app.log', 'w')
print("I am here")
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
Upvotes: 2
Views: 2391
Reputation: 23792
You could find application logs on Kudu
with 2 ways:
1.On the portal:
2.Just access URL directly in the browser:
https://<Your app name>.scm.azurewebsites.net/
Then please check log files in the path :D:\home\LogFiles>
In addition , you could turn on the button to collect logs or store logs in blob container on the portal.
Hope it helps you.
Update Answer :
After some testing, I found that Flask Azure app only records the fastcgi
level logs on KUDU
, although I've turned on the diagnostics log switch which I metioned above. I found C# azure app can record the console log after the diagnostics log configuration, but the azure Python app does not.
As I know , everything you output using print
goes to the standard output(by default).
So , I recommand a workaround to deal with this is to redirect the standard output of your scripts to some files on KUDU:
>>> import sys
>>> sys.stdout = open('<Absolute path on Kudu(such as D:\home\LogFiles\app.log)>', 'w')
>>> print('Hello World!')
You can configure the above code as a global variable.
Upvotes: 3