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