Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chasers committed Jun 30, 2021
1 parent 1fee921 commit d77ee8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 2 additions & 0 deletions logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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
// Vercel log drain was setup to send logs here: https://logflare.app/sources/13830

const { stream, send } = logflarePinoVercel({
apiKey: "eA_3wro12LpZ",
sourceToken: "eb1d841a-e0e4-4d23-af61-84465c808157"
Expand Down
20 changes: 8 additions & 12 deletions pages/api/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,26 @@ import logger from '../../logger/logger'
export default function handler(req, res) {
res.status(200)

// Logging to pino-logflare
logger.info({
data = {
requst: {
method: req.method,
path: req.path
},
response: {
status: res.status
}
}, "Handled response. Logged with pino-logflare.")
}
// Logging to pino-logflare
logger.info(data, "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.")
onlyPino.info(data, "Handled response. Logged with pino.")

// We can also simply parse our object into JSON and log it with console.
console.info(JSON.parse(data), "Handled response. Logged with `console`.")

res.json({ name: 'John Doe' })
}

0 comments on commit d77ee8d

Please sign in to comment.