Skip to content

Instantly share code, notes, and snippets.

@raimohanska
Last active January 18, 2022 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raimohanska/cf0ef4790c1a09044181aac9dbba7850 to your computer and use it in GitHub Desktop.
Save raimohanska/cf0ef4790c1a09044181aac9dbba7850 to your computer and use it in GitHub Desktop.
import nextJs from "next"
async function createNextAppWithCustomLogging() {
const nextApp = nextJs({ dev: false })
const server = (await (nextApp as any).getServer()) as any
if (!(server.logError instanceof Function)) throw Error("Assertion fail")
server.logError = (err: Error) => {
logger.error(err)
}
return nextApp
}
@raimohanska
Copy link
Author

Custom error logging for Next.js custom servers. Next.js doesn't support custom error logging, but this helper will make it possible with Next.js version 12.

@raimohanska
Copy link
Author

raimohanska commented Jan 18, 2022

Note: works only when not running Next.js in dev mode, that's why there's dev: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment