Example for using FilterLogEventsAsync() #2863
Answered
by
bhavya2109sharma
spamulap12
asked this question in
Q&A
-
Hi, I am trying to filter logs based on a search string. I am unable to see all the results with FilterLogEventsAsync(). AWS cli returns expected results. Can you provide an example code to successfully retrieve log events for a log group based on a search string? Below is the example code I tried.============== FilterLogEventsRequest request;
request.SetLogGroupName(logGroupName);
// request.SetLogStreamNames({logStreamName});
// auto startTime = Aws::Utils::DateTime(time(nullptr) - 60 * 60 * 24 * 15);
// request.SetStartTime(startTime.Millis());
// request.SetEndTime(Aws::Utils::DateTime::Now().Millis());
request.SetFilterPattern(pattern);
client->FilterLogEventsAsync(
req,
[this](
const Aws::CloudWatchLogs::CloudWatchLogsClient* /* client */,
const Model::FilterLogEventsRequest& /* request */,
const Model::FilterLogEventsOutcome& outcome,
const std::shared_ptr<
const Aws::Client::AsyncCallerContext>& /* context */) noexcept {
this->runFinished(outcome);
});
if (filterEventsHandler.isSuccess()) {
auto& outcome = filterEventsHandler.getOutcome().GetResult();
const auto& events = outcome.GetEvents();
for (const auto& event : events) {
std::cout << event.GetMessage();
std::cout << event.GetTimestamp();
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
bhavya2109sharma
Oct 17, 2024
Replies: 1 comment
-
Hello @spamulap12 You can try the below code.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jmklix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @spamulap12
You can try the below code.