Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): sdk logging is always present even when not turned on #33324

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/api/aws-auth/sdk-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SdkToCliLogger implements Logger {
private notify(level: 'debug' | 'info' | 'warn' | 'error', ...content: any[]) {
void this.ioHost.notify({
time: new Date(),
level,
level: 'trace', // always log all SDK logs at trace level, no matter what level they are coming from the SDK
action: 'none' as any,
code: 'CDK_SDK_I0000',
message: format('[SDK %s] %s', level, formatSdkLoggerContent(content)),
Expand Down Expand Up @@ -87,7 +87,7 @@ export class SdkToCliLogger implements Logger {
* ```
*/
public error(...content: any[]) {
this.notify('info', ...content);
this.notify('error', ...content);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was also wrong!

}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/aws-cdk/test/api/aws-auth/sdk-logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ describe(SdkToCliLogger, () => {
});

test.each(['trace', 'debug'] as Array<keyof SdkToCliLogger>)('%s method does not call notify', (method) => {
logger[method]('test');
logger[method]('SDK Logger test message');
expect(ioHost.notify).not.toHaveBeenCalled();
});

test.each(['info', 'warn', 'error'] as Array<keyof SdkToCliLogger>)('%s method logs to notify', (method) => {
logger[method]('test');
expect(ioHost.notify).toHaveBeenCalled();
logger[method]('SDK Logger test message');
expect(ioHost.notify).toHaveBeenCalledWith(expect.objectContaining({
level: 'trace',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly expect the the level to be trace

message: `[SDK ${method}] SDK Logger test message`,
}));
});
});

Expand Down