SHARE
TWEET

Untitled

a guest Oct 21st, 2019 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def __init__(self):
  2.       self.log = logging.getLogger("my stuff")
  3.       self.log.setLevel(logging.INFO)
  4.  
  5.       # consoleHandler = logging.StreamHandler()
  6.       # consoleHandler.setLevel(logging.INFO)
  7.  
  8.       fileHandler = logging.FileHandler("alive.log")
  9.       # fileHandler.setLevel(logging.INFO)
  10.  
  11.       # # self.log.addHandler(consoleHandler)
  12.       # self.log.addHandler(fileHandler)
  13.  
  14.       formatter = logging.Formatter('%(asctime)s  %(name)s  %(levelname)s: %(message)s')
  15.       # consoleHandler.setFormatter(formatter)
  16.       fileHandler.setFormatter(formatter)
  17.  
  18.  
  19.       if self.log.hasHandlers():
  20.           self.log.handlers.clear()        # self.log.addHandler(consoleHandler)
  21.       self.log.addHandler(fileHandler)
  22.  
  23.  
  24.       self.log.info('information message')
  25.       self.log.warning("this does not work")
  26.  
  27.  
  28. output:
  29. 2019-10-21 14:24:24,153  my stuff  INFO: information message
  30. 2019-10-21 14:24:24,153 INFO information message
  31. 2019-10-21 14:24:24,153  my stuff  WARNING: this does not work
  32. 2019-10-21 14:24:24,153 WARNING this does not work
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top