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: user configurable logging #870

Closed

Conversation

balazsorban44
Copy link
Member

@balazsorban44 balazsorban44 commented Nov 20, 2020

It adds a new option called logger to the options object taken by NextAuth.

closes #869
closes #907

@vercel
Copy link

vercel bot commented Nov 20, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/21pbqv76n
✅ Preview: https://next-auth-git-feature-configurable-logging.nextauthjs.vercel.app

@vercel vercel bot temporarily deployed to Preview November 20, 2020 22:09 Inactive
Comment on lines 38 to 42
code = code.toLowerCase()
if (userLogger.debug) {
userLogger.debug(code, text)
}
if (process && process.env && process.env._NEXTAUTH_DEBUG) {
Copy link
Member Author

@balazsorban44 balazsorban44 Nov 20, 2020

Choose a reason for hiding this comment

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

I am not checking for process.env._NEXTAUTH_DEBUG here, because if the user implemented the logger.debug method, they probably expect it to be called anyway. In this case, they can decide how debugging logs should be handled/ignored that integrates with the rest of their app's logging. (I for example have my own process.env.LOG_LEVEL env variable, which decides which logs should be sent to my third-pary and which one shouldn't. It also works in a way that when process.env.NODE_ENV is not "production", instead of sending the logs, it will fall back to console)

Comment on lines +49 to +58
setLogger (logger = {}) {
if (typeof logger.error === 'function') {
userLogger.error = logger.error
}
if (typeof logger.warn === 'function') {
userLogger.warn = logger.warn
}
if (typeof logger.debug === 'function') {
userLogger.debug = logger.debug
}
Copy link
Member Author

@balazsorban44 balazsorban44 Nov 20, 2020

Choose a reason for hiding this comment

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

We could make it so that all three methods are required and only accepted together, and provide a nice TypeError to the user if they forgot one or did not define one correctly. I don't have strong opinions about this.

Comment on lines +25 to +27
if (userSuppliedOptions.logger) {
logger.setLogger(userSuppliedOptions.logger)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Providing this in userSuppliedOptions would make this totally backwards compatible and opt-in.

@vercel vercel bot temporarily deployed to Preview November 20, 2020 22:26 Inactive
@balazsorban44
Copy link
Member Author

balazsorban44 commented Nov 26, 2020

Need to handle logger on client side

@vercel vercel bot temporarily deployed to Preview December 4, 2020 23:02 Inactive
@vercel vercel bot temporarily deployed to Preview December 4, 2020 23:03 Inactive
@balazsorban44 balazsorban44 force-pushed the feature/configurable-logging branch from 10b3bf8 to 47d922f Compare December 5, 2020 00:05
@vercel vercel bot temporarily deployed to Preview December 5, 2020 00:06 Inactive
@balazsorban44 balazsorban44 changed the base branch from main to canary December 5, 2020 17:01
@balazsorban44 balazsorban44 added the enhancement New feature or request label Dec 5, 2020
@balazsorban44 balazsorban44 marked this pull request as draft December 5, 2020 17:01
@balazsorban44 balazsorban44 changed the title Introduce user configurable logging feat: user configurable logging Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable logging
1 participant