1개 답변
- 최신
- 최다 투표
- 가장 많은 댓글
0
Cloudwatch Logs Insights has fields auto discovery feature. It automatically discovers fields from some of AWS services, like Lambda as you mentioned. It also discovers all fields in JSON documents. So one of the solutions could be to output logging messages in JSON format. If you are using python, you can configure your logger to use python-json-logger
, or implement json logging yourself.
Let's say we have this kind of messages in Cloudwatch logs:
{
"levelname": "ERROR",
"message": "Some kind of exception occurred",
"funcName": "function_name",
"filename": "app.py"
}
Then you can filter by json fields in CW Logs Insights like this:
fields @timestamp, @message
| filter levelname="ERROR" and funcName="function_name"
| sort @timestamp desc
| limit 20
You can also have nested json in your log messages and filter based on those. Another important part about json logs is to have consistent schema for logging messages across the whole application.
- More about fields discovery and JSON logs - https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_AnalyzeLogData-discoverable-fields.html
- Python JSON logger - https://pypi.org/project/python-json-logger/
답변함 2년 전
관련 콘텐츠
- AWS 공식업데이트됨 9달 전
- AWS 공식업데이트됨 2년 전
- AWS 공식업데이트됨 2년 전