#! /usr/bin/python3
import logging
class Trace():
"""
Implement a trace decorator module.
"""
def __init__(self):
self.logger = logging.getLogger(__name__)
self.debug = False
self.indent = ""
def trace(self, func):
def wrapper():
if self.debug:
self.indent = self.indent + " "
self.logger.warning("%sEntering %s" % (self.indent, func.__name__))
func()
if self.debug:
self.logger.warning("%sExiting %s" % (self.indent, func.__name__))
x = len(self.indent) - 2
self.indent = self.indent[0:x]
return wrapper
if __name__ == "__main__":
tracker = Trace()
tracker.debug = True
@tracker.trace
def myfunc():
print("I am here!")
myfunc()