1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, and you can use docs.python.org/library/… for how to log to a single file from multiple processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.