I'm doing my first NextJS project, and currently looking at logging. Looking around, I found this blog post, which suggests configuring Pino to log the commit SHA in each message. This makes sense to me for a lot of reasons. The question is, how do I get the SHA when Next is doing its static build? In the blog example, they're deploying on Vercel, and get it from there:
const logger = pino({
base: {
env: process.env.NODE_ENV,
revision: process.env.VERCEL_GITHUB_COMMIT_SHA,
},
});
But I almost certainly will not be deploying on Vercel. Equally, there's lots of documentation on how to generate a custom build ID, which comes down to doing something like this in next.config.js:
const nextConfig = {
generateBuildId: async () => {
const buildId = await determineBuildId()
console.log(`> Build ID: ${buildId}`)
return buildId
},
}
But I can't find any documentation on how to actually access the buildId within Next, so that it's a constant in my logging:
const logger = pino({
base: {
env: process.env.NODE_ENV,
revision: // how do I access the generated buildId here?
},
});
This really must just be a failing of my google-fu, because this seems like it should be common practice, but ... I can't find it. Any ideas? Or pointers to documentation?