python django logging problem

I use logging settings as below in the settings.py file:


logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT);

handler = logging.handlers.RotatingFileHandler( LOG_FILE_PATH, 'a', LOG_FILE_SIZE,LOG_FILE_NUM );

formatter = logging.Formatter ( LOG_FORMAT );

handler.setFormatter(formatter);

logging.getLogger().addHandler(handler)


and i use mod_python with apache2.

the problem is: when the log rotate, i got many log files created at the same time. for example, i set 5 work-process in apache, and i got log.1, log.2 ... log.5 when it rotate.

any suggestions?


RotatingFileHandler is not designed to work in multiprocess system. Each process you have notice that file is too large and starts new log, so you get up to 5 new logs. It's not as easy to implement it properly: you have to obtain interprocess lock before creating new file and inform each process to reopen it. You'd better use external (provided with your OS) rotation with server restart or setup single-process logging server.

链接地址: http://www.djcxy.com/p/54680.html

上一篇: 懒惰的记录器消息字符串评估

下一篇: python django日志记录问题