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
4 changed files
with
58 additions
and
7 deletions.
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,13 @@ | ||
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) { | ||
console.error(e) | ||
} | ||
|
||
res.status(200).json({ error: 'true' }) | ||
} |
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,22 @@ | ||
// 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) | ||
|
||
const data = { | ||
request: { | ||
method: req.method, | ||
url: req.url | ||
}, | ||
response: { | ||
status: res.statusCode | ||
} | ||
} | ||
|
||
// 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' }) | ||
} |
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,22 @@ | ||
// 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) | ||
|
||
const data = { | ||
request: { | ||
method: req.method, | ||
url: req.url | ||
}, | ||
response: { | ||
status: res.statusCode | ||
} | ||
} | ||
|
||
// Logging to pino-logflare | ||
logger.info(data, "Handled response. Logged with pino-logflare.") | ||
|
||
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