Hi guys,
I'm using the python built-in logging module in a django project. Using dictConfig, the configuration in settings.py is like this:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(ROOT_DIR(), 'django.log'),
'maxBytes': 1024 * 1024 * 10,
'backupCount': 5,
'formatter': 'verbose',
},
}
'formatters': {
'verbose': {
'format': '######################################################################\n'
'%(levelname)s | %(asctime)s | %(process)s | %(module)s | %(name)s.%(funcName)s:%(lineno)d | \n%(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'simple': {
'format': '%(levename)s | %(asctime)s | %(message)s'
},
},
'loggers': {
'django': {
'handlers': ['console', 'logfile'],
'level': 'INFO',
},
'django.request': {
'handlers': ['console', 'mail_admins'],
'level': 'ERROR',
'propagate': False
},
'project_name': {
'handlers': ['console', 'logfile'],
'level': 'DEBUG',
'propagate': True,
},
'utility': {
'handlers': ['console', 'logfile'],
'level': 'DEBUG',
'propagate': True,
},
}
}
LOGGING_CONFIG = None
import logging.config
logging.config.dictConfig(LOGGING)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And I use logger = logging.getLogger(__name__) in the code under 'project_name' module.
And I find it causes huge memory leak problem, the memory usage keeps growing and never goes down.
if I replace the
logger.info() part with a simple print() function, the memory usage is small and stable, so I guess it's the logging module that should to blame.
So I used objgraph to detect if the Logger type numbers kept growing, but the result suggested that no obvious leaking types.
I've been in this situation for almost a week, and still can't work it out.
Anyone can give me some hints on this?
Thanks!
YP