I have a class in python with lot of methods as follows:
import logging
logger = logging.getLogger(__name__)
class BaseWorkFlow:
def __init__(self, response=None):
self.response = response
def func1(self):
self.response = 10
logger.info(self.response.data)
def func2(self):
self.response = 20
logger.info(self.response.data)
def func3(self):
self.response = 20
logger.info(self.response.data)
As is evident, every time the value of self.response changes, I need to log it. Currently i am using explicit logging statements to do this.However, now my code is littered with log statements.Also it is very difficult to update log statements manually when new methods are added.
Is there any way of writing a function or a decorator that automatically does the logging operation anytime self.response is assigned a new value in any of the class methods ?