Where can I check tornado's log file?

前端 未结 4 589
旧巷少年郎
旧巷少年郎 2020-12-28 20:57

I think there was a default log file, but I didn\'t find it yet.

Sometimes the HTTP request process would throw an exception on the screen, but I suggest it also goe

相关标签:
4条回答
  • 2020-12-28 21:00

    There's no logfile by default.

    You can use the --log_file_prefix=PATH command line option to set one.

    Tornado just uses the Python stdlib's logging module, if you're trying to do anything more complicated.

    0 讨论(0)
  • Use RotatingFileHandler:

    import logging
    from logging.handlers import RotatingFileHandler
    
    log_path = "/path/to/tornado.access.log"
    logger_ = logging.getLogger("tornado.access")
    logger_.setLevel(logging.INFO)
    logger_.propagate = False
    handler = RotatingFileHandler(log_path, maxBytes=1024*1024*1024, backupCount=3)
    handler.setFormatter(logging.Formatter("[%(name)s][%(asctime)s][%(levelname)s][%(pathname)s:%(lineno)d] > %(message)s"))
    logger_.addHandler(handler)
    
    0 讨论(0)
  • 2020-12-28 21:18

    It uses standard python logging module by default.

    Here is definition:

    access_log = logging.getLogger("tornado.access")
    app_log = logging.getLogger("tornado.application")
    gen_log = logging.getLogger("tornado.general")
    

    It doesn't write to files by default. You can run it using supervisord and define in supervisord config, where log files will be located. It will capture output of tornado and write it to files.

    Also you can think this way:

    tornado.options.options['log_file_prefix'].set('/opt/logs/my_app.log')
    tornado.options.parse_command_line()
    

    But in this case - measure performance. I don't suggest you to write to files directly from tornado application, if it can be delegated.

    FYI: parse_command_line just enables pretty console logging.

    0 讨论(0)
  • 2020-12-28 21:18

    With newer versions, you may do

    args = sys.argv
    args.append("--log_file_prefix=/opt/logs/my_app.log")
    tornado.options.parse_command_line(args)
    

    or as @ColeMaclean mentioned, providing

    --log_file_prefix=PATH 
    

    at command line

    0 讨论(0)
提交回复
热议问题