How to print the logs in the Python tornado frame by date

Source: Internet
Author: User

This article mainly introduces the method of printing the log in the Python tornado frame by date, and the friends who need it can refer to the following

When web traffic comes up, logs are easier to view and manage on a daily or even hourly basis, and Python's logging module also provides timedrotatingfilehandler to support archiving logs in different time dimensions.

However, according to logging Howto's official guide set, but found that the new log only left root, tornado internal logger all did not take effect.

Referring to an answer on StackOverflow, I found that the following configuration can be used to tornado internal logger also timedrotatingfilehandler:


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 # Logging.yaml Version:1 disable_existing_loggers:false formatters:simple:format: '% (asctime) s-% (name) s-% (Leveln AME) S-% (message) s ' loggers:all:handlers: [All] propagate:false tornado:handlers: [All] propagate:false handlers : Console:class:logging. Streamhandler level:info formatter:simple stream:ext://sys.stdout all:class: Logging.handlers.TimedRotatingFileHandler level:info formatter:simple when:midnight filename:./logs/server.log root : Level:info handlers: [Console, all] Propagate:true

Just call at the Tornado entry code:


1 Logging.config.dictConfig (Yaml.load) (Open (' Logging.yaml ', ' r '))

If you want to divide the log by another time dimension, you can change the value of the When parameter.

Special note: When the value is D, indicating that the server started the time, every 24 hours archived once; and if you, like me, want to archive the log in the wee hours of the day, you can configure it as midnight.

The CentOS system may need to install Python-yaml:sudo yum Install first Python-yaml

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.