Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import logging;
- def loggingDemo():
- """Just demo basic usage of logging module
- """
- logging.info("You should see this info both in log file and cmd window");
- logging.warning("You should see this warning both in log file and cmd window");
- logging.error("You should see this error both in log file and cmd window");
- logging.debug("You should ONLY see this debug in log file");
- return;
- def initLogging(logFilename):
- logging.basicConfig(level=logging.DEBUG, format='LINE %(lineno)-4d %(levelname)-8s %(message)s',
- datefmt='%m-%d %H:%M', filename=logFilename, filemode='w');
- console = logging.StreamHandler();
- console.setLevel(logging.DEBUG);
- formatter = logging.Formatter('LINE %(lineno)-4d : %(levelname)-8s %(message)s');
- console.setFormatter(formatter);
- logging.getLogger('').addHandler(console);
- ###############################################################################
- if __name__ == "__main__":
- logFilename = "crifan_logging_demo.log"
- initLogging(logFilename)
- loggingDemo()
Add Comment
Please, Sign In to add comment