Skip to content

Instantly share code, notes, and snippets.

@mmasztalerczuk
Last active June 6, 2016 18:25
Show Gist options
  • Save mmasztalerczuk/e04c6c8c0572c59bf4519e5ca13cbf2d to your computer and use it in GitHub Desktop.
Save mmasztalerczuk/e04c6c8c0572c59bf4519e5ca13cbf2d to your computer and use it in GitHub Desktop.
import logging
def createLogger(name):
logger = logging.getLogger(name)
hdlr = logging.FileHandler('test.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
return logger
class A():
def __init__(self):
self.logger = createLogger("A")
self.logger.info("Hello A!")
class B():
def __init__(self):
self.logger = createLogger("B")
self.logger.info("Hello B!")
a = A()
b = B()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment