Guest User

Untitled

a guest
Jul 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import logging;
  4.  
  5. def loggingDemo():
  6. """Just demo basic usage of logging module
  7.     """
  8.  
  9. logging.info("You should see this info both in log file and cmd window");
  10. logging.warning("You should see this warning both in log file and cmd window");
  11. logging.error("You should see this error both in log file and cmd window");
  12.  
  13. logging.debug("You should ONLY see this debug in log file");
  14. return;
  15.  
  16. def initLogging(logFilename):
  17. logging.basicConfig(level=logging.DEBUG, format='LINE %(lineno)-4d  %(levelname)-8s %(message)s',
  18. datefmt='%m-%d %H:%M', filename=logFilename, filemode='w');
  19.  
  20. console = logging.StreamHandler();
  21. console.setLevel(logging.DEBUG);
  22. formatter = logging.Formatter('LINE %(lineno)-4d : %(levelname)-8s %(message)s');
  23. console.setFormatter(formatter);
  24. logging.getLogger('').addHandler(console);
  25. ###############################################################################
  26. if __name__ == "__main__":
  27. logFilename = "crifan_logging_demo.log"
  28. initLogging(logFilename)
  29. loggingDemo()
Add Comment
Please, Sign In to add comment