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
| import logging
from logging import config
LOGGING_COnFIG= {
"version": 1,
"formatters": {
"default": {
'format': '%(asctime)19.19s %(levelname)1.1s %(message)s',
},
"file": {
'format': '%(asctime)19.19s %(filename)s %(lineno)s %(levelname)1.1s %(message)s',
},
"plain": {
"format": "%(message)s",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "default",
},
"file": {
"class": "logging.FileHandler",
"level": 20,
"filename": "./log.txt",
"formatter": "default",
},
"rotate_file": {
"class": "logging.handlers.RotatingFileHandler",
"level": 20,
"filename": "./log.txt",
"formatter": "default",
"maxBytes": 52428800,
"backupCount": 7,
}
},
"loggers": {
"tmp": {
"handlers": ["console", "rotate_file"],
"level": "INFO",
"propagate": False,
},
},
"disable_existing_loggers": True,
}
config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger("tmp")
logger.info("吃\ud83d\udc3a") |