简体   繁体   中英

How i can get different logger for each call of function?

I need a different logger for each call of same function.

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

How i can organize logging in myfunction for that? Is it possible?

You could always:

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

But, I agree with Vinay - this is an antipattern!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM