Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #289 add documentation and typescript definitions for res.log #290

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const logger = require('pino-http')({
function handle (req, res) {
logger(req, res)
req.log.info('something else')
res.log.info('just in case you need access to logging when only the response is in scope')
res.end('hello world')
}

Expand Down Expand Up @@ -300,6 +301,7 @@ http.createServer((req, res) => {
res[logger.startTime] = Date.now()
someImportantThingThatHasToBeFirst(req, res)
logger(req, res)
res.log.info('log is available on both req and res');
res.end('hello world')
}).listen(3000)
```
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ declare module "http" {

interface OutgoingMessage {
[startTime]: number;
log: pino.Logger;
allLogs: pino.Logger[];
}
}
5 changes: 5 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const stdSerializedResults: StdSerializedResults = {
123: {},
},
req: {
params: {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the typescript errors.

query: {},
id: canBeUndefined('id'),
method: 'GET',
url: 'http://0.0.0.0',
Expand All @@ -159,5 +161,8 @@ const httpServerListener: RequestListener = (request, response) => {
request.allLogs[0].info("Request Received");
// res[startTime] should be available
response[startTime] = Date.now();
// res.log and res.allLogs should be available
response.log.info("Logging works on response");
request.allLogs[0].info("allLogs available on response");
response.end("Hello world");
};