Skip to content

Commit

Permalink
fix(cli): sdk logging is always present even when not turned on (#33324)
Browse files Browse the repository at this point in the history
### Issue #33320

Closes #33320

### Reason for this change

In #33273 we introduced a bug that causes SDK logs to always be printed.

### Description of changes

Set the correct log level for SDK logs.

### Describe any new or updated permissions being added

n/a

### Description of how you validated changes

Manual test and updated unit test

### 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*
  • Loading branch information
mrgrain authored Feb 6, 2025
1 parent 80217f1 commit 29a9a6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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);
}
}

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',
message: `[SDK ${method}] SDK Logger test message`,
}));
});
});

Expand Down

0 comments on commit 29a9a6d

Please sign in to comment.