Skip to content

Instantly share code, notes, and snippets.

@finloop
Forked from oseme-techguy/docker_output.py
Created June 22, 2022 17:42
Show Gist options
  • Save finloop/0d4c8bf3af3729c961418f382a158ec8 to your computer and use it in GitHub Desktop.
Save finloop/0d4c8bf3af3729c961418f382a158ec8 to your computer and use it in GitHub Desktop.
Docker Python logger output to stdout
import logging
from sys import stdout
# Define logger
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG) # set logger level
logFormatter = logging.Formatter\
("%(name)-12s %(asctime)s %(levelname)-8s %(filename)s:%(funcName)s %(message)s")
consoleHandler = logging.StreamHandler(stdout) #set streamhandler to stdout
consoleHandler.setFormatter(logFormatter)
logger.addHandler(consoleHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment