You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary of proposed feature
A clear and concise description of the feature being proposed.
Make it possible for the user to decide how/where to log messages by next-auth, on all level.
Purpose of proposed feature
A clear and concise description description of why this feature is necessary and what problems it solves.
next-auth already gives us the possibility to log some errors when they arise, through the
error event handler (although I am not sure when and where this is called, @iaincollins. I would even argue, that this proposal would make events.error unnecessary, but that would make the feature a breaking change. I need your opinion on this). I think we can get a bit further, if we make it possible for the user to decide where to send all the logs put out by next-auth. You see, when the Next.js app gets deployed somewhere, logging to the console will probably be lost or at least hard to reach. I propose a way for the user to get hold of those logs, and let them send it to somewhere else, like a third-party logging service.
Detail about proposed feature
A detailed description of how the proposal might work (if you have one).
importNextAuthfrom'next-auth'importmyLoggerfrom"my-logger"constoptions={logger: {error(params){myLogger.error(params,"{code}: {text} ({link})")},warn(params){myLogger.warn(params,"{code}: {text} ({link})")},debug(params){myLogger.debug(params,"{code}: {text}")},}asLogger}exportdefault(req,res)=>NextAuth(req,res,options)interfaceLogParams{code: stringtext: stringlink?: string}// This is the form of the logger, not required by user, could be added to `@types/next-auth`interfaceLogger{error?: (params: LogParams)=>voidwarn?: (params: LogParams)=>voiddebug?: (params: LogParams)=>void}
Here, when myLogger#{level} is called, it will send that message to a third party logging server.
Its implementation is less relevant than the signature of the logger methods, But here I provided the format which our logger takes. The first argument is an object, the second is the actual message, where I can reference values from the object. The message is shown first in our logger service, and on click it will also expand the object. In case myLogger has the same signature as logger expects, the user could simply do :
The idea is, that the user could provide as many of these methods as they want, so if they only define error inside logger, then warn and debug will keep logging to console. Or we could require the user to provide all 3 levels all the time, for consistency.
Potential problems
Describe any potential problems or potential limitations or caveats that might apply to the proposed solution.
This can be implemented in a backward-compatible way, so no problems arise.
Describe any alternatives you've considered
When having a problem with next-auth, I can only debug it locally, cause accessing the logs in our deployment environment is not always easy (For example a Docker container in Azure App Service)
Additional context
Any other context, screenshots, etc.
Please indicate if you are willing and able to help implement the proposed feature.
Summary of proposed feature
A clear and concise description of the feature being proposed.
Make it possible for the user to decide how/where to log messages by
next-auth
, on all level.Purpose of proposed feature
A clear and concise description description of why this feature is necessary and what problems it solves.
next-auth
already gives us the possibility to log some errors when they arise, through theerror event handler (although I am not sure when and where this is called, @iaincollins. I would even argue, that this proposal would make
events.error
unnecessary, but that would make the feature a breaking change. I need your opinion on this). I think we can get a bit further, if we make it possible for the user to decide where to send all the logs put out bynext-auth
. You see, when the Next.js app gets deployed somewhere, logging to the console will probably be lost or at least hard to reach. I propose a way for the user to get hold of those logs, and let them send it to somewhere else, like a third-party logging service.Detail about proposed feature
A detailed description of how the proposal might work (if you have one).
Here is how I can see the user facing API, following the signatures of built-in
console
logger functions at https://github.com/nextauthjs/next-auth/blob/main/src/lib/logger.js:Here, when
myLogger#{level}
is called, it will send that message to a third party logging server.Its implementation is less relevant than the signature of the
logger
methods, But here I provided the format which our logger takes. The first argument is an object, the second is the actual message, where I can reference values from the object. The message is shown first in our logger service, and on click it will also expand the object. In casemyLogger
has the same signature aslogger
expects, the user could simply do :The idea is, that the user could provide as many of these methods as they want, so if they only define
error
insidelogger
, thenwarn
anddebug
will keep logging toconsole
. Or we could require the user to provide all 3 levels all the time, for consistency.Potential problems
Describe any potential problems or potential limitations or caveats that might apply to the proposed solution.
This can be implemented in a backward-compatible way, so no problems arise.
Describe any alternatives you've considered
When having a problem with
next-auth
, I can only debug it locally, cause accessing the logs in our deployment environment is not always easy (For example a Docker container in Azure App Service)Additional context
Any other context, screenshots, etc.
Please indicate if you are willing and able to help implement the proposed feature.
Implemented in #870
Would love to here your thoughts!
The text was updated successfully, but these errors were encountered: