Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lstroud/690af6e99b820294e88e1d689f903e98 to your computer and use it in GitHub Desktop.
Save lstroud/690af6e99b820294e88e1d689f903e98 to your computer and use it in GitHub Desktop.
Change Python logger format in AWS Lambda
# Python logger in AWS Lambda has a preset format. To change the format of the logging statement, remove the logging handler
# and add a new handler with the required format
logger = logging.getLogger()
for h in logger.handlers:
logger.removeHandler(h)
h = logging.StreamHandler(sys.stdout)
# use whatever format you want here
FORMAT = '%(asctime)s %(message)s'
h.setFormatter(logging.Formatter(FORMAT))
logger.addHandler(h)
logger.setLevel(logging.INFO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment