Skip to content

Instantly share code, notes, and snippets.

@guma44
Created February 2, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guma44/e8c2ca26241c87179b1eb97e8ffb70e9 to your computer and use it in GitHub Desktop.
Save guma44/e8c2ca26241c87179b1eb97e8ffb70e9 to your computer and use it in GitHub Desktop.
Set up auto-tracing for a class
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