Created
October 22, 2014 06:56
-
-
Save mottosso/6158ffeac47cc150d070 to your computer and use it in GitHub Desktop.
Logging in The Foundy Modo
This file contains 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
#python | |
import logging | |
# Pick up the "root" logger | |
log = logging.getLogger() | |
# In addition, Modo doesn't come with a handler; handlers | |
# are the objects actually performing any printing. So we'll | |
# add a vanilla handler that simply prints what the user asks | |
# along with a prefix of which level the message is at. | |
formatter = logging.Formatter("%(levelname)s %(message)s") | |
# "StreamHandler" just means it prints to the console (i.e. | |
# stdout). Alternative handlers may log to files or across | |
# a network. | |
stream_handler = logging.StreamHandler() | |
stream_handler.setFormatter(formatter) | |
log.addHandler(stream_handler) | |
# The root logger in Modo has been initialised at a | |
# level above INFO, which means it will only print | |
# messages in the WARNING-CRITICAL range | |
log.setLevel(logging.INFO) | |
# Finally, at the INFO level, print something. | |
log.info("Logging works!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment