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

feat(logging): add isLoggable util #12977

Open
wants to merge 5 commits into
base: central-logger
Choose a base branch
from

Conversation

ashwinkumar6
Copy link
Contributor

@ashwinkumar6 ashwinkumar6 commented Feb 7, 2024

Description of changes

  • Add loggableHelpers to resolve LoggingConstraints in cloudwatch configuration.
  • Add unit tests for the same
  • expose other required utils

PS: WIP, to be rebased on top of #12907

Description of how you validated changes

Unit tests with all scenarios

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashwinkumar6 ashwinkumar6 changed the title chore(logger): rename core 'Logger' to lower case (#12762) feat(logging): add isLoggable util Feb 7, 2024
@ashwinkumar6 ashwinkumar6 changed the base branch from central-logger to logging/PR-12907 February 8, 2024 18:46
@ashwinkumar6 ashwinkumar6 marked this pull request as ready for review February 8, 2024 18:47
@ashwinkumar6 ashwinkumar6 requested review from a team as code owners February 8, 2024 18:47
@ashwinkumar6 ashwinkumar6 changed the base branch from logging/PR-12907 to central-logger February 10, 2024 00:34
@ashwinkumar6 ashwinkumar6 requested a review from a team as a code owner February 10, 2024 00:34
Copy link
Contributor

@jimblanc jimblanc left a 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'),
Copy link
Contributor

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

Copy link
Contributor Author

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

categoryLogLevel: { Auth: 'WARN', Storage: 'DEBUG' },
};
expect(
await resolveLoggingConstraints(authErrorLog, loggingConstraints),
Copy link
Contributor

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)

Copy link
Contributor Author

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();
Copy link
Contributor

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

Copy link
Contributor Author

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,
};
}

ashwinkumar6 and others added 4 commits March 4, 2024 18:45
…Helpers.test.ts

Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
…Helpers.test.ts

Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
…Helpers.test.ts

Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants