diff --git a/logger/logger.js b/logger/logger.js index e99f48b..27f7390 100644 --- a/logger/logger.js +++ b/logger/logger.js @@ -20,7 +20,7 @@ const logger = pino({ }, level: "debug", base: { - env: process.env.ENV || "ENV not set", + env: process.env.NODE_ENV, revision: process.env.VERCEL_GITHUB_COMMIT_SHA, }, }, stream); diff --git a/pages/api/error-console.js b/pages/api/error-console.js index 6f26ca1..d246e72 100644 --- a/pages/api/error-console.js +++ b/pages/api/error-console.js @@ -3,6 +3,7 @@ import logger from '../../logger/logger' export default function handler(req, res) { // Lets log an error with console here. + try { throw new Error('Whoops!') } catch (e) { diff --git a/pages/api/error-pino-logflare.js b/pages/api/error-pino-logflare.js index f0d3357..4e61b6e 100644 --- a/pages/api/error-pino-logflare.js +++ b/pages/api/error-pino-logflare.js @@ -3,6 +3,7 @@ import logger from '../../logger/logger' export default function handler(req, res) { // Lets log an error with pino-logflare here. + try { throw new Error('Whoops! Error with pino-logflare.') } catch (e) { diff --git a/pages/api/error-pino.js b/pages/api/error-pino.js index 0c39d88..5d172e2 100644 --- a/pages/api/error-pino.js +++ b/pages/api/error-pino.js @@ -3,6 +3,7 @@ import logger from '../../logger/logger' export default function handler(req, res) { // Lets log an error with pino here. + try { throw new Error('Whoops! Error with pino.') } catch (e) { diff --git a/pages/api/hello-console.js b/pages/api/hello-console.js index 0626087..d5aaa2a 100644 --- a/pages/api/hello-console.js +++ b/pages/api/hello-console.js @@ -1,7 +1,5 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import logger from '../../logger/logger' - export default function handler(req, res) { res.status(200) @@ -16,6 +14,7 @@ export default function handler(req, res) { } // We can also simply parse our object into JSON and log it with console. + console.info(JSON.stringify(data), "Handled response. Logged with `console`.") res.json({ name: 'John Doe' }) diff --git a/pages/api/hello-pino-logflare.js b/pages/api/hello-pino-logflare.js index 607bec4..7c00389 100644 --- a/pages/api/hello-pino-logflare.js +++ b/pages/api/hello-pino-logflare.js @@ -1,7 +1,5 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import logger from '../../logger/logger' - export default function handler(req, res) { res.status(200) @@ -16,6 +14,7 @@ export default function handler(req, res) { } // Logging to pino-logflare + logger.info(data, "Handled response. Logged with pino-logflare.") res.json({ name: 'John Doe' }) diff --git a/pages/api/hello-pino.js b/pages/api/hello-pino.js index dfc61e4..e95bbf7 100644 --- a/pages/api/hello-pino.js +++ b/pages/api/hello-pino.js @@ -1,7 +1,5 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import logger from '../../logger/logger' - export default function handler(req, res) { res.status(200) @@ -17,6 +15,7 @@ export default function handler(req, res) { // Logging with straight pino. // Both will end up in Vercel's log drains with slight different payloads. + const onlyPino = require('pino')() onlyPino.info(data, "Handled response. Logged with pino.")