Created
February 7, 2017 19:44
-
-
Save svrist/92314c495310cbef1bd02ff95a474214 to your computer and use it in GitHub Desktop.
serverless framework friendly logformat
This file contains hidden or 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
from __future__ import division, print_function, unicode_literals | |
import logging | |
import os | |
def setup_logging(): | |
'serverless framework friendly logformat' | |
if 'LAMBDA_TASK_ROOT' not in os.environ: | |
return | |
logger = logging.getLogger() | |
fmt = ( | |
'%(asctime)s.%(msecs)3d (Z)\t%(aws_request_id)s\t' | |
'[%(name)s:%(funcName)s]\t[%(levelname)s]\t%(message)s\n' | |
) | |
datefmt = '%Y-%m-%d %H:%M:%S' | |
for hand in logger.handlers: | |
hand.setFormatter(logging.Formatter(fmt, datefmt=datefmt)) | |
logger.setLevel(logging.DEBUG) | |
# Silence Boto a bit | |
logging.getLogger('boto3').setLevel(logging.WARNING) | |
logging.getLogger('botocore').setLevel(logging.WARNING) | |
logging.getLogger('s3transfer').setLevel(logging.WARNING) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment