Skip to content

Commit 81fe660

Browse files
authored
fix(custom-resources): use loggingFormat instead of deprecated logFormat (#35015)
Use loggingFormat instead of deprecated logFormat in the Provider class ### Issue # (if applicable) Closes #35002 ### Reason for this change The `logFormat` property in Lambda Function is deprecated and will be removed in the next major release. This change updates the Provider class to use the recommended `loggingFormat` property instead, eliminating deprecation warnings. ### Description of changes - Updated the Provider class in `provider.ts` to use `loggingFormat` instead of the deprecated `logFormat` property - Added a test in `provider.test.ts` to verify that no deprecation warnings are emitted when creating a Provider - Ensured backward compatibility by maintaining the same functionality This change is minimal and focused on replacing the deprecated property with its recommended alternative. The functionality remains the same, but the code now follows best practices and avoids deprecation warnings. ### Describe any new or updated permissions being added No new or updated IAM permissions are needed for this change. ### Description of how you validated changes - Added a unit test that verifies no deprecation warnings are emitted when using the Provider class - Manually verified that the Provider class still functions correctly with the new property - Ensured backward compatibility by testing with existing code ### 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 ef477dd commit 81fe660

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/aws-cdk-lib/custom-resources/lib/provider-framework/provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ export class Provider extends Construct implements ICustomResourceProvider {
324324
handler: `framework.${entrypoint}`,
325325
timeout: FRAMEWORK_HANDLER_TIMEOUT,
326326

327-
logFormat: lambda.LogFormat.JSON,
327+
// Using loggingFormat instead of deprecated logFormat which will be removed in the next major release
328+
loggingFormat: lambda.LoggingFormat.JSON,
328329
applicationLogLevelV2: loggingLevel,
329330
// props.logRetention is deprecated, make sure we only set it if it is actually provided
330331
// otherwise jsii will print warnings even for users that don't use this directly

packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,37 @@ test('Log level are set to FATAL by default', () => {
365365
});
366366
});
367367

368+
test('uses loggingFormat instead of deprecated logFormat', () => {
369+
// GIVEN
370+
// Spy on console.warn to check for deprecation warnings
371+
// eslint-disable-next-line no-console
372+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
373+
374+
const stack = new Stack();
375+
const handler = new lambda.Function(stack, 'MyHandler', {
376+
code: new lambda.InlineCode('foo'),
377+
handler: 'index.onEvent',
378+
runtime: lambda.Runtime.NODEJS_LATEST,
379+
});
380+
381+
try {
382+
// WHEN
383+
new cr.Provider(stack, 'MyProvider', {
384+
onEventHandler: handler,
385+
});
386+
387+
// THEN
388+
// Check that no deprecation warnings related to logFormat were emitted
389+
const deprecationWarnings = warnSpy.mock.calls
390+
.filter(args => typeof args[0] === 'string' && args[0].includes('logFormat is deprecated'));
391+
392+
expect(deprecationWarnings.length).toBe(0);
393+
} finally {
394+
// Clean up
395+
warnSpy.mockRestore();
396+
}
397+
});
398+
368399
describe('retry policy', () => {
369400
const stack = new Stack();
370401

0 commit comments

Comments
 (0)