SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import logging
  2. import sys
  3.  
  4. DEBUG_LOG_FILENAME = "info.log"
  5.  
  6. # set up formatting
  7. formatter = logging.Formatter("%(levelname)-5s %(asctime)s %(module)s.%(funcName)s() [%(lineno)d]: %(message)s",
  8.                               "%Y-%m-%d %H:%M:%S")
  9.  
  10. # set up logging to STDOUT for all levels DEBUG and higher
  11. sh = logging.StreamHandler(sys.stdout)
  12. sh.setLevel(logging.DEBUG)
  13. sh.setFormatter(formatter)
  14.  
  15. # set up logging to a file for all levels DEBUG and higher
  16. fh = logging.FileHandler(DEBUG_LOG_FILENAME)
  17. fh.setLevel(logging.DEBUG)
  18. fh.setFormatter(formatter)
  19.  
  20. # create Logger object
  21. mylogger = logging.getLogger('MyLogger')
  22. mylogger.setLevel(logging.DEBUG)
  23. mylogger.addHandler(sh)    # enabled: stdout
  24. mylogger.addHandler(fh)    # enabled: file
  25.  
  26. # create shortcut functions
  27. debug = mylogger.debug
  28. info = mylogger.info
  29. warning = mylogger.warning
  30. error = mylogger.error
  31. critical = mylogger.critical
  32.  
  33. if __name__ == "__main__":
  34.     # its usage:
  35.     for i in range(100):
  36.         if i % 5 == 0:
  37.             info("i is {i}".format(i=i))
  38.         if i % 50 == 0:
  39.             debug("i is {i}".format(i=i))
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