-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(logging): add isLoggable util #12977
base: central-logger
Are you sure you want to change the base?
feat(logging): add isLoggable util #12977
Conversation
dfc2d2c
to
bafa9c1
Compare
bafa9c1
to
c7f481f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Few nits & questions
|
||
jest.mock('@aws-amplify/core', () => { | ||
return { | ||
...jest.requireActual('@aws-amplify/core'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we get by without the requireActual
? Not sure what else from core we might need to mock for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, we can add additional mocks to items imported from core if required to make it more evident on what's being used. Removed requireActual
packages/logging/__tests__/providers/cloudwatch/utils/loggableHelpers.test.ts
Outdated
Show resolved
Hide resolved
packages/logging/__tests__/providers/cloudwatch/utils/loggableHelpers.test.ts
Outdated
Show resolved
Hide resolved
packages/logging/__tests__/providers/cloudwatch/utils/loggableHelpers.test.ts
Outdated
Show resolved
Hide resolved
categoryLogLevel: { Auth: 'WARN', Storage: 'DEBUG' }, | ||
}; | ||
expect( | ||
await resolveLoggingConstraints(authErrorLog, loggingConstraints), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: resolves.toBe
might be a little cleaner for this use-case (here and elsewhere in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks good callout, makes sense to use this when dealing with async functions.
Updated in all places
const { defaultLogLevel, categoryLogLevel, userLogLevel } = | ||
loggingConstraints; | ||
|
||
const { userSub = '' } = await fetchAuthSession(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't undefined be a more appropriate default value here? We could check that it is set before checking userLogLevel
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, we could keep userSub as string | undefined
instead of defaulting to a empty string just to be sure. And add an additional condition to the if block as shown below
const { userSub } = await fetchAuthSession();
if (userSub && userLogLevel?.[userSub]) {
return {
defaultLogLevel: userLogLevel[userSub].defaultLogLevel,
categoryLogLevel: userLogLevel[userSub]?.categoryLogLevel,
};
}
…Helpers.test.ts Co-authored-by: Jim Blanchard <[email protected]>
…Helpers.test.ts Co-authored-by: Jim Blanchard <[email protected]>
…Helpers.test.ts Co-authored-by: Jim Blanchard <[email protected]>
Description of changes
LoggingConstraints
in cloudwatch configuration.PS: WIP, to be rebased on top of #12907
Description of how you validated changes
Unit tests with all scenarios
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.