Skip to content

Commit 2d1e718

Browse files
authored
chore: enable log timestamps by default (#32448)
### Reason for this change timestamps were no longer being printed for debug and trace level logging messages, because as part of the logging changes, I incidentally removed the timestamps from the `debug()` and `trace()` functions. ### Description of changes Re-added timestamps for whenever those 2 methods are called i.e. ``` debug: "message" is now "[09:58:24] message" info: "message" is still "message" ``` which was the previous functionality ### Description of how you validated changes Modified relevant unit tests and also did manual testing by verifying outputs of cdk commands on different cdk versions ``` # running cdk synth from local build of bobertzh/logging-fix [15:08:06] CDK toolkit version: 0.0.0 (build 68b77e7) [15:08:06] Command line arguments: { ... Resources: CDKMetadata: ... ``` ``` # running cdk synth from live CDK toolkit version: 2.173.0 (build b5c2189) Command line arguments: { ... Resources: CDKMetadata: ... ``` ``` # running cdk synth from be000a2 (parent commit) [15:20:33] CDK toolkit version: 0.0.0 (build be000a2) [15:20:33] Command line arguments: { ... Resources: CDKMetadata: ... ``` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 043f9db commit 2d1e718

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/aws-cdk/lib/logging.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,17 @@ export const data = (fmt: string, ...args: unknown[]) => log({
173173
message: util.format(fmt, ...args),
174174
forceStdout: true,
175175
});
176-
export const debug = (fmt: string, ...args: unknown[]) => log(LogLevel.DEBUG, fmt, ...args);
177-
export const trace = (fmt: string, ...args: unknown[]) => log(LogLevel.TRACE, fmt, ...args);
176+
export const debug = (fmt: string, ...args: unknown[]) => log({
177+
level: LogLevel.DEBUG,
178+
message: util.format(fmt, ...args),
179+
timestamp: true,
180+
});
181+
182+
export const trace = (fmt: string, ...args: unknown[]) => log({
183+
level: LogLevel.TRACE,
184+
message: util.format(fmt, ...args),
185+
timestamp: true,
186+
});
178187

179188
export const success = (fmt: string, ...args: unknown[]) => log({
180189
level: LogLevel.INFO,

packages/aws-cdk/test/api/logs/cli-logging.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ describe('logging', () => {
8181

8282
setLogLevel(LogLevel.DEBUG);
8383
debug('debug message');
84-
expect(mockStderr).toHaveBeenCalledWith('debug message\n');
84+
expect(mockStderr).toHaveBeenCalledWith(
85+
expect.stringMatching(/^\[\d{2}:\d{2}:\d{2}\] debug message\n$/),
86+
);
8587
});
8688

8789
test('trace messages only show at trace level', () => {
@@ -91,7 +93,9 @@ describe('logging', () => {
9193

9294
setLogLevel(LogLevel.TRACE);
9395
trace('trace message');
94-
expect(mockStderr).toHaveBeenCalledWith('trace message\n');
96+
expect(mockStderr).toHaveBeenCalledWith(
97+
expect.stringMatching(/^\[\d{2}:\d{2}:\d{2}\] trace message\n$/),
98+
);
9599
});
96100
});
97101

0 commit comments

Comments
 (0)