9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS Lambda (Python) でログレベルを環境変数から注入

Last updated at Posted at 2018-05-16
lambda_function.py
import logging
import os

logger = logging.getLogger(__name__)
logger.setLevel(os.getenv('LOG_LEVEL', 'WARNING'))

def lambda_handler(event, context):
    logger.debug('debug')
    logger.info('info')
    logger.warning('warning')
    logger.error('error')
    logger.critical('critical')

環境変数LOG_LEVELを変える(DEBUGやINFOなど)とそのレベル以上のメッセージが出力され、何も設定していないとWARNINGが設定される.
logging.setLevel()の引数に文字列が入れられるのがミソの模様.

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?