0

I want to create task-specific log files that reflect what's happening during a particular operation, but I want these logging messages to also go to the primary Django log.

My current solution, which seems to work fine at first glance, is something like:

logger = getLogger("%s:%s" % (__name__, task_id))
handler = FileHandler(task_log_file)
logger.addHandler(handler)

# Work

logger.removeHandler(handler)

As I said, this works, but the main issue that occurs to me is that this logger isn't really temporary -- from what I've read of logging.Manager each logger will just hang around indefinitely until shutdown. In this case, when I'm done I know I won't use the logger again (okay, technically I might, but that will be rare), and assuming the system is stable this could be running through hundreds of thousands of tasks.

Is there a "right" way to do this?

4

1 回答 1

0

您可以有一种方法来标记和清除您的日志记录资源文件,或者只使用单例模式。

于 2013-02-22T03:18:04.937 回答