I pushed a web app to Azure. It worked on my computer, but not on Azure. To debug it, I'd like to read what the app printed on Azure. How can I view Azure's logs?
Were it Heroku, I'd run heroku logs
On the Azure 'portal' I found a URL In the Azure 'portal' I found a URL 'FTP DIAGNOSTIC LOGS ' ftp://waws-prod-db3-003.ftp.azurewebsites.windows.net/LogFiles but couldn't manage to connect to it. I think our poxy office firewall blocks ftp.
I tried
azure site log tail
but I get a meaningless error message
error: Forbidden
Windows Azure Web Sites log streaming will stream information written to any text file in the D:/home/logfiles
directory of your web site. So the requirement is that your application writes its log files to this directory. The streaming support is fairly generic, and can stream any text file that lives under the LogFiles folder. But for it to work, the file needs to be readable, so if it’s opened exclusively, it won’t work.
In Python this can be somewhat challenging to do considering that there can be multiple instances of your application running concurrently, so file locking may be an issue.
A workaround for this is to use ConcurrentLogHandler, which will allow concurrent write access to the log files. This requires pywin32 (Python for Windows extensions), which is not installed by default on Windows Azure Websites, so you'll have to include that dependency along with your application. Be sure to include the appropriate version for the Python runtime used by Windows Azure Websites (at this time, Python 2.7 32 bits).
The DjangoWAWSLogging sample project shows how to do that. See settings.py and views.py. As explained in the project's README, at this time the log can only be downloaded when the website is stopped. This is probably due to the fact that ConcurrentLogHandler has the file open in exclusive mode. Refer to this question.
This fragment from settings.py
configures the log handler, using the LOGFILE
environment variable as the file name:
'ConcurrentLogHandler':{
'level': 'DEBUG',
'class': 'cloghandler.ConcurrentRotatingFileHandler',
'formatter': 'verbose',
'filename': os.getenv('LOGFILE', 'django.log')
},
Since log streaming can handle multiple files at the same time, it's probably a better strategy to have each website instance log to a different file, like this:
'handlers': {
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(os.getenv('LOGPATH', "."), str(uuid.uuid1()) + ".log"),
'maxBytes': 1024 * 1024,
'backupCount': 9,
'formatter': 'standard',
},
},
Where LOGPATH is an environment variable configured in Windows Azure Websites as "D:\home\logfiles".
This configuration by itself still doesn't solve the issue, probably because, according to Python's documentation, under Windows "logging opens the files with exclusive locks".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With