Created
February 2, 2017 08:26
-
-
Save guma44/e8c2ca26241c87179b1eb97e8ffb70e9 to your computer and use it in GitHub Desktop.
Set up auto-tracing for a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from autologging import traced, TRACE | |
import logging | |
import sys | |
from logging import FileHandler | |
formatter = logging.Formatter(fmt="%(asctime)s - %(levelname)s:%(name)s:%(funcName)s:%(message)s") | |
console_handler = logging.StreamHandler() | |
console_handler.setFormatter(formatter) | |
logger = logging.getLogger(__name__) | |
logger.setLevel(TRACE) | |
logger.addHandler(console_handler) | |
logfile_handler = FileHandler("logfile.log") | |
logfile_handler.setFormatter(formatter) | |
logger.addHandler(logfile_handler) | |
@traced(logger) | |
class A(object): | |
arg = 'A' | |
def a(self): | |
print "I am", self.arg | |
@traced | |
class B(A): | |
arg = 'B' | |
def b(self, print_me='Hello!'): | |
print print_me | |
if __name__ == '__main__': | |
a = A() | |
a.a() | |
b = B() | |
b.a() | |
b.b(print_me='Hello B!') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment