Log to screen: Print output at debug levelset the level=logging to DEBUG Code: import logging
# get logging setup: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# print a basic message in DEBUG logging.debug('> This is a log message.')
# print a message with a variable in INFO + DEBUG y = "my variable" logging.info('> text & {}'.format(y)) output: 2015-11-02 17:50:49,349 - DEBUG - > This is a log message.
2015-11-02 17:50:49,349 - INFO - > text & my variable
Process finished with exit code 0
print output at info level: Just set the level=logging to INFO code import logging
# get logging setup: logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# print a basic message in DEBUG logging.debug('> This is a log message.')
# print a message with a variable in INFO + DEBUG y = "my variable" logging.info('> text & {}'.format(y))
output 2015-11-02 17:52:58,798 - INFO - > text & my variable
Process finished with exit code 0
References: |
|