Skip to content

Commit

Permalink
Support structured logs from lambda (requires latest TF AWS provider)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesJJ committed Dec 23, 2023
1 parent ec9e516 commit 34f428d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lambda.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from pythonjsonlogger import jsonlogger
import urllib.parse
import botocore
import boto3
Expand All @@ -12,12 +11,17 @@
import time
import json

# JSON Logs
logger = logging.getLogger()
logHandler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter()
logHandler.setFormatter(formatter)
logger.addHandler(logHandler)
# JSON Logs (Lambda handles this automatically, the import is for local execution)
try:
from pythonjsonlogger import jsonlogger

logger = logging.getLogger()
logHandler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter()
logHandler.setFormatter(formatter)
logger.addHandler(logHandler)
except ImportError:
pass

# Logging Levels
boto3.set_stream_logger(name="botocore", level=logging.WARN)
Expand Down

0 comments on commit 34f428d

Please sign in to comment.