Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14126

Can Python logging write the name of the current function?

$
0
0

Is there a way to configure logging to automatically prefix the logged information with the current function name (=the function currently in execution when logger.info is called)?

import logginglogging.basicConfig(level=logging.DEBUG)logger = logging.getLogger()class A:    def foo(self):        logger.info("hello")    def bar(self):        logger.info("world")    a = A()a.foo()  # should output: ... foo: helloa.bar()  # should output: ... bar: world

Viewing all articles
Browse latest Browse all 14126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>