TimedRotatingFileHandler doesn't work fine in Django with multi-instance

前端 未结 1 1474
清酒与你
清酒与你 2020-12-06 02:41

I use TimedRotatingFileHandler to logging Django log and rotate every day, but check the log file, strange issue is yesterday log is truncated and logging few today\'s log,

相关标签:
1条回答
  • 2020-12-06 02:48

    You should not be logging to a file-based handler from multiple processes concurrently - that is not supported, as there is no portable OS support for it.

    To log to a single destination from multiple processes, you can use one of the following approaches:

    • Use something like ConcurrentLogHandler
    • Use a SysLogHandler (or NTEventLogHandler on Windows)
    • Use a SocketHandler which sends the logs to a separate process for writing to file
    • Use a QueueHandler with a multiprocessing.Queue, as outlined here.
    0 讨论(0)
提交回复
热议问题