Blame view
log.py
1.27 KB
c4176e46d add file |
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 |
# coding: utf-8 from os import path import logging.config def init_log(log_dir, debug=False): if not path.exists(log_dir): print 'log path is not exist:%s' % log_dir exit(-1) config = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'default': { 'format': '%(levelname)s %(asctime)s %(module)s:%(funcName)s:%(lineno)d %(message)s' }, 'simple': { 'format': '%(level)s %(message)s' } }, 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'default', }, 'file': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'filename': path.join(log_dir, 'webapp.log'), 'maxBytes': 1024 * 1024 * 50, 'backupCount': 5, 'formatter': 'default', }, }, 'loggers': { 'starmachine': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': False, }, } } logging.config.dictConfig(config) |