2. (10 pts) Suppose, we need to debug somebody else\'s program. We suspect that
ID: 3600388 • Letter: 2
Question
2. (10 pts) Suppose, we need to debug somebody else's program. We suspect that there is a problem with the method wizbang ) in class Widget or with how that method is called. We cannot modify class Widget, nor can we modify the client code that contains the calls to Widget.wizbang), since Widget obje and we can create new classes. In order to better understand what this method does, we would like to print the values of the parameters and the return value into a log file every time Widget.wizbang is called. Explain, how you would produce this log file given the constraints that neither class Widget nor the client can be modified.Explanation / Answer
I would use a Logger framework such as slf4j in Java.
Then to log the parameters of the function i would simply print the calling parameters to the log file befor the execution of the method and after the execution would print the returned value.
/** The Constant LOGGER declaration as the global variable */
private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);
//Calling of the function
LOGGER.debug("wizbang method called with following parameters :{} ", parameter1);
result = Widget.wizbang(parameter1);
LOGGER.debug("wizbang method returned :{} ", result);
Hope this helps!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.