I am trying to setup a format for logging in python:
import logging,logging.handlers FORMAT = "%(asctime)-15s %(message)s" logging.basicConfig(format=FORMAT,level=logging.INFO) logger = logging.getLogger("twitter") handler = logging.handlers.RotatingFileHandler('/var/log/twitter_search/message.log', maxBytes=1024000, backupCount=5) logger.addHandler(handler)
Basically, logging works, but without the date format...
You can add the datefmt
parameter to basicConfig
:
logging.basicConfig(format=FORMAT,level=logging.INFO,datefmt='%Y-%m-%d %H:%M:%S')
Or, to set the format for the Rotating FileHandler:
fmt = logging.Formatter(FORMAT,datefmt='%Y-%m-%d') handler.setFormatter(fmt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With