forked from Logflare/next-pino-logflare-logging-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pino from 'pino' | ||
import { logflarePinoVercel } from 'pino-logflare' | ||
|
||
// create pino-logflare console stream for serverless functions and send function for browser logs | ||
// Browser logs are going to: https://logflare.app/sources/13989 | ||
const { stream, send } = logflarePinoVercel({ | ||
apiKey: "eA_3wro12LpZ", | ||
sourceToken: "eb1d841a-e0e4-4d23-af61-84465c808157" | ||
}); | ||
|
||
// create pino loggger | ||
const logger = pino({ | ||
browser: { | ||
transmit: { | ||
level: "info", | ||
send: send, | ||
} | ||
}, | ||
level: "debug", | ||
base: { | ||
env: process.env.ENV || "ENV not set", | ||
revision: process.env.VERCEL_GITHUB_COMMIT_SHA, | ||
}, | ||
}, stream); | ||
|
||
export default logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
// 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).json({ name: 'John Doe' }) | ||
res.status(200) | ||
|
||
// Logging to pino-logflare | ||
logger.info({ | ||
requst: { | ||
method: req.method, | ||
path: req.path | ||
}, | ||
response: { | ||
status: res.status | ||
} | ||
}, "Handled response. Logged with pino-logflare.") | ||
|
||
// Logging with pino. Both will end up in Vercel's log drains with slight different payloads. | ||
// Both will end up Logflare if a log drain is setup. | ||
const onlyPino = require('pino')() | ||
|
||
onlyPino.info({ | ||
requst: { | ||
method: req.method, | ||
path: req.path | ||
}, | ||
response: { | ||
status: res.status | ||
} | ||
}, "Handled response. Logged with pino.") | ||
|
||
res.json({ name: 'John Doe' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters