简体   繁体   English

如何将 logging.info 和 logging.debug 输出到控制台?

[英]How to output logging.info and logging.debug to console?

I can only see warning and error, how can I get info and debug printed out?我只能看到警告和错误,如何获取信息和调试信息? To clarify, I am starting the tornado app with python app.py .为了澄清python app.py ,我正在使用python app.py启动python app.py应用程序。 I want the info and debug logs to print out to the console after I run the app.我希望在运行应用程序后将信息和调试日志打印到控制台。

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('hello fun fun test world from tornado super')
        logging.info('info')
        logging.warning('warning')
        logging.error('error')
        logging.debug('debug')


application = tornado.web.Application([(r"/", MainHandler)], debug=True)

You probably need to change the level of the logging module to allow for debug and info messages to be displayed in the console.您可能需要更改日志模块的级别以允许在控制台中显示调试和信息消息。

logger.setLevel(logging.DEBUG) # this should allow all messages to be displayed

if you don't want to display debug messages then do this:如果您不想显示调试消息,请执行以下操作:

logger.setLevel(logging.INFO)

And just a quick fyi.只是一个快速的参考。 Here are the levels in order, so if you set one of them it will display any messages of the types below the set level and it will NOT any messages above the set level.这是按顺序排列的级别,因此如果您设置其中一个级别,它将显示低于设置级别的任何类型的消息,而不会显示高于设置级别的任何消息。

logging.DEBUG
logging.INFO
logging.WARNING
logging.ERROR
logging.CRITICAL

By calling tornado.options.parse_command_line you register tornado command line flags.通过调用tornado.options.parse_command_line您可以注册 tornado 命令行标志。

You can use logging command line flag to change logging level from command line.您可以使用logging命令行标志从命令行更改日志记录级别。

For more information: https://stackoverflow.com/a/14269208/63097更多信息: https : //stackoverflow.com/a/14269208/63097

python helloworld.py --logging=debug

Here's the trick: you can directly modify tornados internal access logger:诀窍如下:您可以直接修改 tornados 内部访问记录器:

import logging
import tornado
import tornado.log

tornado.log.access_log.setLevel(logging.DEBUG)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM