Azure默认日志 [英] Azure Default Logs

查看:68
本文介绍了Azure默认日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Azure的新手,并且已将Flask应用程序部署到Azure.只是很好奇,如果我在应用程序中打印(控制台日志)某些内容,Azure会将日志保存在哪里.只是想知道默认情况下是否有任何日志文件夹,还是我必须设置一个自己的日志文件夹?如果是这样,我该如何创建一个?

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()

推荐答案

您可以通过以下两种方法在Kudu上找到应用程序日志:

You could find application logs on Kudu with 2 ways:

1.在门户网站上:

2.只需直接在浏览器中访问URL:

2.Just access URL directly in the browser:

https://<Your app name>.scm.azurewebsites.net/

然后请检查路径:D:\home\LogFiles>

此外,您可以打开按钮以收集日志或将日志存储在门户网站上的blob容器中.

In addition , you could turn on the button to collect logs or store logs in blob container on the portal.

希望它对您有帮助.

更新答案:

Update Answer :

经过一些测试,我发现Flask Azure应用程序仅在KUDU上记录了fastcgi级别的日志,尽管我已经打开了上面提到的诊断日志开关.我发现C#azure应用程序可以在配置诊断日志后记录控制台日志,但是azure Python应用程序不能.

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.

据我所知,使用print输出的所有内容都将进入标准输出(默认情况下).

As I know , everything you output using print goes to the standard output(by default).

因此,我建议一种解决方法是将脚本的标准输出重定向到KUDU上的某些文件:

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.

这篇关于Azure默认日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆