0

对于同一函数的每次调用,我需要一个不同的记录器。

loggerA = logging.getLogger('whatever1')
myfunction('A')
loggerB = logging.getLogger('whatever2')
myfunction('B')
# The loggers must not cross

我如何为此组织登录 myfunction?可能吗?

4

1 回答 1

0

你总是可以:

def myfunction(some_arg):
    logger = logging.getLogger("myfunction." + str(some_arg))
    # whatever else

但是,我同意 Vinay 的观点——这是一种反模式!

于 2013-09-12T06:18:59.733 回答