#!/usr/bin/env python # -*- coding: utf-8 -*- """ @Time :2021/9/20 17:06 @Author :维斯 @File :log.py @Version :1.0 @Function: """ import logging.config class MyLog: @staticmethod def get(): log = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'default': { 'format': '%(asctime)s %(levelname)s %(name)s %(message)s' }, }, 'handlers': { 'file': { 'class': 'logging.handlers.TimedRotatingFileHandler', 'level': 'DEBUG', 'formatter': 'default', 'filename': 'log', 'when': 'D', # 分割单位 S-秒;M-分;H-小时;D-天;W{0-6}-周(0-6为周一到周六,0表示周一) 'encoding': 'utf-8', }, }, 'root': { 'handlers': ['file'], 'level': 'INFO', }, } return logging.getLogger(logging.config.dictConfig(log)) if __name__ == '__main__': MyLog.get().info('info') MyLog.get().debug('debug') MyLog.get().warning('warning') MyLog.get().error('error')