-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nextauthjs/next-auth/21pbqv76n |
src/lib/logger.js
Outdated
code = code.toLowerCase() | ||
if (userLogger.debug) { | ||
userLogger.debug(code, text) | ||
} | ||
if (process && process.env && process.env._NEXTAUTH_DEBUG) { |
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.
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
)
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 | ||
} |
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.
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.
if (userSuppliedOptions.logger) { | ||
logger.setLogger(userSuppliedOptions.logger) | ||
} |
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.
Providing this in userSuppliedOptions
would make this totally backwards compatible and opt-in.
Need to handle |
10b3bf8
to
47d922f
Compare
It adds a new option called
logger
to theoptions
object taken byNextAuth
.closes #869
closes #907