Last Updated: February 25, 2016
·
34.45K
· toumorokoshi

Creating a python logger to stdout

import logging
import sys
log = logging.getLogger(__name__)
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
out_hdlr.setLevel(logging.INFO)
log.addHandler(out_hdlr)
log.setLevel(logging.INFO)

Then you can do:

log.debug("NO")
log.error("THIS IS AN ERROR")

1 Response
Add your response

.ERROR should be .error

over 1 year ago ·