添加uuid供请求,直到在CloudWatch日志中响应
我将日志从Gradle Project推到CloudWatch。该配置看起来好像
"logDriver": "awslogs",
"options": {
"awslogs-datetime-format": "%Y-%m-%d %H:%M:%S%L",
"awslogs-region": "ap-southeast-1",
"awslogs-stream-prefix": "ecs",
"awslogs-group": "/ecs/xxxx"
}
}
我想向每个日志推动一些UUID,以便可以将每个请求区分开直至其响应。
基本上,我正在寻找log4j2.yml文件中的%x REGEX之类的东西,其中我们刚刚在MDC上下文中设置了一个UUID,并且为每个日志打印。
如何配置CloudWatch配置以使用唯一的标识符来进行日志,以供请求进行响应?
我看到适当的正则加载项。
I am pushing logs from gradle project to Cloudwatch. The configuration looks like
"logDriver": "awslogs",
"options": {
"awslogs-datetime-format": "%Y-%m-%d %H:%M:%S%L",
"awslogs-region": "ap-southeast-1",
"awslogs-stream-prefix": "ecs",
"awslogs-group": "/ecs/xxxx"
}
}
I want to push some UUID to each log so that I can distinguish each request till its response.
Basically, I am looking for something like %X regex in log4j2.yml file where we just set a UUID in MDC context and it is printed for every log.
How can I configure cloudwatch config to use unique identifier for logs for request till response?
I saw this but I am not finding any proper regex to add-in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您想为每个请求创建一个唯一的日志流,而简单的答案是您不能。
您正在使用
awslogs
驱动程序,该驱动程序是在容器启动时配置的,并且在容器运行时不会更改。如果您使用默认值(STDOUT/STDERR)记录并在EC2实例上运行,则可以使用代理配置来执行此操作,但这真的是一个坏主意。我假设您的容器处理Web请求。在这种情况下,如果您确实将某些内容组合在一起以将每个请求发送到另一个流,则将发生:
createLogStream
每秒50个请求的节流率。defict> DeficteLogStreams
中达到配额。相反,我建议您通过MDC在应用程序中添加您的请求,然后使用 CloudWatch logs Insights 提取单个请求的消息。
It seems like you want to create a unique log stream for each request, and the simple answer is that you can't.
You're using the
awslogs
driver, which is configured at the time the container starts, and does not change while the container is running. You could possibly do this with an agent configuration if you use default (stdout/stderr) logging and are running on an EC2 instance, but that would be a really bad idea.I'm assuming that your container processes web requests. In which case, if you did hack something together to send each request to a different stream, here's what would happen:
CreateLogStream
throttling rate of 50 requests per second.DescribeLogStreams
.Instead, I recommend that you add your UUID to your request inside your app, via the MDC, and use CloudWatch Logs Insights to extract the messages for a single request.