python log config sample
前言
任何项目都要有日志,无日志不服务。如果是独立部署的python程序,需要自行配置logger
配置
logging.ini
[loggers] keys=root [logger_root] handlers=screen,file level=INFO [formatters] keys=simple,complex [formatter_simple] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s [formatter_complex] format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s [handlers] keys=file,screen [handler_file] class=handlers.RotatingFileHandler backupCount=3 maxBytes=20*1024*1024 formatter=complex level=DEBUG args=('dog.log',) [handler_screen] class=StreamHandler formatter=simple level=INFO args=(sys.stdout,)
主要是设置了滚动,最大值,格式等。一般这个可以满足standalone的python程序
使用
import logging.config logging.config.fileConfig("logging.ini") logger = logging.getLogger("test") def test(): logger.info("test")
sort of, I have some experience in the domain of database(MySQL/mongo), java, python, front-end, etc. I'll willing to give and accept bits of help from others.
now base in Singapore.