diff --git a/packages/aws-cdk/lib/api/logs/logs-monitor.ts b/packages/aws-cdk/lib/api/logs/logs-monitor.ts index 51cd54137091c..f6f2086bc20bf 100644 --- a/packages/aws-cdk/lib/api/logs/logs-monitor.ts +++ b/packages/aws-cdk/lib/api/logs/logs-monitor.ts @@ -182,8 +182,9 @@ export class CloudWatchLogEventMonitor { limit: 100, startTime: startTime, }).promise(); + const filteredEvents = response.events ?? []; - for (const event of response.events ?? []) { + for (const event of filteredEvents) { if (event.message) { events.push({ message: event.message, @@ -200,9 +201,9 @@ export class CloudWatchLogEventMonitor { // if we have > 100 events let the user know some // messages have been supressed. We are essentially // showing them a sampling (10000 events printed out is not very useful) - if (response.nextToken) { + if (filteredEvents.length > 0 && response.nextToken) { events.push({ - message: '(...messages supressed...)', + message: '>>> `watch` shows only the first 100 log messages - the rest have been truncated...', logGroupName, timestamp: new Date(endTime), }); diff --git a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts index 84a96da3525ad..becb3d97dfbf3 100644 --- a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts +++ b/packages/aws-cdk/test/api/logs/logs-monitor.test.ts @@ -55,7 +55,7 @@ test('continue to the next page if it exists', async () => { `[${blue('loggroup')}] ${yellow(HUMAN_TIME)} message`, ); expect(stderrMock.mock.calls[1][0]).toContain( - `[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} (...messages supressed...)`, + `[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} >>> \`watch\` shows only the first 100 log messages - the rest have been truncated...`, ); });