diff --git a/packages/aws-cdk/lib/logging.ts b/packages/aws-cdk/lib/logging.ts index 52c914d927e0e..fd1b8e5d0f47d 100644 --- a/packages/aws-cdk/lib/logging.ts +++ b/packages/aws-cdk/lib/logging.ts @@ -173,8 +173,17 @@ export const data = (fmt: string, ...args: unknown[]) => log({ message: util.format(fmt, ...args), forceStdout: true, }); -export const debug = (fmt: string, ...args: unknown[]) => log(LogLevel.DEBUG, fmt, ...args); -export const trace = (fmt: string, ...args: unknown[]) => log(LogLevel.TRACE, fmt, ...args); +export const debug = (fmt: string, ...args: unknown[]) => log({ + level: LogLevel.DEBUG, + message: util.format(fmt, ...args), + timestamp: true, +}); + +export const trace = (fmt: string, ...args: unknown[]) => log({ + level: LogLevel.TRACE, + message: util.format(fmt, ...args), + timestamp: true, +}); export const success = (fmt: string, ...args: unknown[]) => log({ level: LogLevel.INFO, diff --git a/packages/aws-cdk/test/api/logs/cli-logging.test.ts b/packages/aws-cdk/test/api/logs/cli-logging.test.ts index 08300a7e64890..bce7a9b35f231 100644 --- a/packages/aws-cdk/test/api/logs/cli-logging.test.ts +++ b/packages/aws-cdk/test/api/logs/cli-logging.test.ts @@ -81,7 +81,9 @@ describe('logging', () => { setLogLevel(LogLevel.DEBUG); debug('debug message'); - expect(mockStderr).toHaveBeenCalledWith('debug message\n'); + expect(mockStderr).toHaveBeenCalledWith( + expect.stringMatching(/^\[\d{2}:\d{2}:\d{2}\] debug message\n$/), + ); }); test('trace messages only show at trace level', () => { @@ -91,7 +93,9 @@ describe('logging', () => { setLogLevel(LogLevel.TRACE); trace('trace message'); - expect(mockStderr).toHaveBeenCalledWith('trace message\n'); + expect(mockStderr).toHaveBeenCalledWith( + expect.stringMatching(/^\[\d{2}:\d{2}:\d{2}\] trace message\n$/), + ); }); });