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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| mport logging.config import settings
def get_logger(name): logging.config.dictConfig(settings.LOGGING_DIC)
logger = logging.getLogger(name) return logger
logger = get_logger("交易相关")
logger.info("egon给刘老师转了一个亿")
""" logging配置 """
LOG1_PATH = 'a1.log' LOG2_PATH = 'a2.log'
fm1 = '%(asctime)s - %(filename)s:%(lineno)d - %(name)s - %(levelname)s: %(message)s' fm2 = "%(asctime)s : %(message)s"
LOGGING_DIC = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'formatter1': { 'format': fm1 }, 'formatter2': { 'format': fm2 }, }, 'filters': {}, 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'formatter2' }, 'fh1': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'formatter': 'formatter1', 'filename': LOG1_PATH, 'encoding': 'utf-8', }, 'fh2': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'formatter': 'formatter1', 'filename': LOG2_PATH, 'encoding': 'utf-8', }, }, 'loggers': { '': { 'handlers': ['console','fh1','fh2'], 'level': 'DEBUG', 'propagate': False, }, '用户相关': { 'handlers': ['console','fh1'], 'level': 'DEBUG', 'propagate': False, }, }, }
|