You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lot of our Lambda log messages are in JSON format, which parse nicely in CloudWatch insights, but we want to migrate everything over to centralized logging. We were able to modify the LogPipelineLogProcessorFn code in util/log_parser.py for one of our Lambdas to make this work:
class Lambda(LogType):
"""An implementation of LogType for Lambda Function Logs"""
_fields = [
"time",
"log_group",
"log_stream",
"owner",
"log-detail",
]
def parse(self, line) -> list:
json_records = []
data_str = "[{}]".format(line.replace("}{", "},{"))
try:
data_json = json.loads(data_str)
except json.JSONDecodeError as e:
logger.error(e)
return json_records
for i in range(len(data_json)):
if data_json[i]["messageType"] != "DATA_MESSAGE":
# logger.info("Skipping Kinesis Firehose Test Message.")
continue
log_group = data_json[i].get("logGroup")
log_stream = data_json[i].get("logStream")
owner = data_json[i].get("owner")
for log_event in data_json[i].get("logEvents"):
json_record = {}
timestamp = log_event["timestamp"]
log_message = log_event.get("message")
json_record["log_group"] = log_group
json_record["log_stream"] = log_stream
json_record["owner"] = owner
json_record["log-detail"] = log_message
json_record["time"] = timestamp
# Parse message JSON into a new field
try:
log_message_json = json.loads(log_message)
json_record["message_json"] = log_message_json
except json.JSONDecodeError as e:
logger.info("Skipping non-json log")
json_records.append(json_record)
return json_records
Is there an easier way to do this, or do we need to modify the code for all of the log processor functions that get generated?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
A lot of our Lambda log messages are in JSON format, which parse nicely in CloudWatch insights, but we want to migrate everything over to centralized logging. We were able to modify the
LogPipelineLogProcessorFn
code inutil/log_parser.py
for one of our Lambdas to make this work:Is there an easier way to do this, or do we need to modify the code for all of the log processor functions that get generated?
Beta Was this translation helpful? Give feedback.
All reactions