Skip to content

Commit

Permalink
Fix: #289 add documentation and typescript definitions for res.log (#290
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jmealo committed Jul 28, 2023
1 parent f4c4afb commit 3b0d314
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
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: {},
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");
};

0 comments on commit 3b0d314

Please sign in to comment.