SHARE
TWEET

rmst

a guest Oct 21st, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import logging
  2.  
  3. class Wat:
  4.  
  5.       def __init__(self):
  6.             print("--- rmstar for life ---")
  7.  
  8.             self.log = logging.getLogger("my stuff")
  9.             self.log.setLevel(logging.INFO)
  10.  
  11.             # consoleHandler = logging.StreamHandler()
  12.             # consoleHandler.setLevel(logging.INFO)
  13.  
  14.             fileHandler = logging.FileHandler("alive.log")
  15.             # fileHandler.setLevel(logging.INFO)
  16.  
  17.             # # self.log.addHandler(consoleHandler)
  18.             # self.log.addHandler(fileHandler)
  19.  
  20.             formatter = logging.Formatter('%(asctime)s  %(name)s  %(levelname)s: %(message)s')
  21.             # consoleHandler.setFormatter(formatter)
  22.             fileHandler.setFormatter(formatter)
  23.  
  24.  
  25.             if self.log.hasHandlers():
  26.                 self.log.handlers.clear()        # self.log.addHandler(consoleHandler)
  27.             self.log.addHandler(fileHandler)
  28.  
  29.  
  30.             self.log.info('information message')
  31.             self.log.warning("this does not work")
  32.  
  33. if __name__ == '__main__':
  34.     w = Wat()
  35.  
  36.  
  37. '''
  38. $ python rmstar.py
  39. --- rmstar for life ---
  40. '''
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