Add indent to loguru logs if produced by a nested call of a class

15 Views Asked by At

I have a python class called A(), which has methods. Classes B(A) and C(A) inherit from base class A(), and have other methods. I instanciate b = B() into C. If every one of these classes has loguru logs in its methods, how can I indent each call level?

For example:

class A():       
    def __init__(self):
        pass                      
    def m_a(self):                
        logger.info("this is m_a")
                                                                                  
class B(A):                       
    def __init__(self):
        pass
    def m_b(self):                
        logger.info("this is m_b")

class C(A):
    def __init__(self):
        pass
    def m_c(self):
        ma = self.m_a()
        logger.info("this is m_c")
        b = B()
        mb = b.m_b()

c = C()
c.m_c()

I obtain

INFO - this is m_a
INFO - this is m_c
INFO - this is m_a
INFO - this is m_b

How can I obtain instead

INFO - this is m_a
INFO - this is m_c
INFO -   this is m_a
INFO -   this is m_b
0

There are 0 best solutions below