Last active
October 12, 2019 13:03
-
-
Save kmondesir/6fe92792ca6cfda36fcdc5ff4f4e4ef3 to your computer and use it in GitHub Desktop.
Adds logging to Python scripts
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
{ | |
"Adds logic for logging": { | |
"prefix": "log", | |
"body": [ | |
"import logging as log", | |
"severity = {", | |
"\t\t\t\t\t\t'CRITICAL': 50,", | |
"\t\t\t\t\t\t'ERROR': 40,", | |
"\t\t\t\t\t\t'WARNING': 30,", | |
"\t\t\t\t\t\t'INFO': 20,", | |
"\t\t\t\t\t\t'DEBUG': 10,", | |
"\t\t\t\t\t\t'NOTSET': 0,", | |
"}", | |
"", | |
"logger = log.getLogger(__name__)", | |
"formatter = log.Formatter('%(asctime)s:%(name)s:%(message)s')", | |
"", | |
"file_handler = log.FileHandler(\"$TM_FILENAME\")", | |
"file_handler.setLevel(severity[\"${1:|DEBUG,INFO,WARNING|}\"])", | |
"file_handler.setFormatter(formatter)", | |
"", | |
"stream_handler = log.StreamHandler()", | |
"stream_handler.setFormatter(formatter)", | |
"", | |
"logger.addHandler(file_handler)", | |
"logger.addHandler(stream_handler)", | |
"$0" | |
], | |
"description": "Adds logic for logging" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Included escaped quote characters surrounding the VSCode user snippet variables as well as the choice tab stop. I had also included the $0 at the end of the snippet to be able to tab to the end of the line.