Last active
September 8, 2016 17:30
-
-
Save deckerego/1edae6b7ac2a9a69ac23a29f29de0b92 to your computer and use it in GitHub Desktop.
Sensibly log things in Python, using console stdout when necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
RED='\033[0;31m' | |
CYAN='\033[0;36m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
logger = logging.getLogger('myapp') | |
logfile = logging.FileHandler('warnings.log') | |
logfile.setLevel(logging.WARNING) | |
logger.addHandler(logfile) | |
console = logging.StreamHandler() | |
console.setLevel(logging.ERROR) | |
logger.addHandler(console) | |
print "Doing an important task" | |
logger.error("Something terrible happened!") | |
logger.warning("Eh, look at this later.") | |
printf "\n${CYAN}*** DONE${NC}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment