yuliji
4/18/2017 - 8:51 AM

python logging

python logging

LOGGING = {
    "version": 1,
    "formatters": {
        'default': {
            'format': '%(asctime)s %(name)-6s %(levelname)-8s %(message)s'}
    },
    "handlers": {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'default',
            'level': 'DEBUG'
        },
        'server_file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.WatchedFileHandler',
            'formatter': 'default',
            'filename': './wmd.log',
        #    'filename': os.path.join(LOG_ROOT_DIR, django_log_file_name),

            'encoding': 'utf8'
        },
        'access_file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.WatchedFileHandler',
            'formatter': 'default',
            'filename': './wmd_access.log',
        #    'filename': os.path.join(LOG_ROOT_DIR, django_log_file_name),

            'encoding': 'utf8'
        },
    },
    "loggers": {
        'tornado.access': {
            'handlers': ['access_file'],
            'level': 'INFO',
            'propagate': False,
        }
    },
    "root": {
        'handlers': ['console', 'server_file'],
        'level': 'DEBUG',
    },
}


import settings
import logging
from logging.config import dictConfig
dictConfig(settings.LOGGING)