question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] logger.assign does not add properties to "request completed" log.

See original GitHub issue

[x] I’ve read the docs of nestjs-pino

[x] I’ve read the docs of pino

[x] I couldn’t find the same open issue of nestjs-pino

What is the current behavior?

When I call this.logger.assign({ someKey: someValue }), the key is properly added to the logs that belong to a request except the one that marks the end of the request “Request completed”.

What is the expected behavior?

I would expect that the method this.logger.assign({ someKey: someValue }) adds the key and value to all the logs belonging to that request.

Please mention other relevant information such as Node.js version and Operating System.

I am using nestjs-pino 2.2.0.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
iamoleggacommented, Nov 12, 2021

Unfortunately, after spending a whole day on this I could not find a solution. I believe this feature should be made on pino-http first without adding any workarounds. Will add this limitation to docs

1reaction
iamoleggacommented, Nov 12, 2021

Just checked such example:

const express = require('express');
const pinoHttp = require('pino-http');

const app = express();

app.use(pinoHttp({ prettyPrint: true }));

app.get('/', (req, res) => {
  req.log = req.log.child({ foo: 'bar' });
  res.send('foo bar');
});

app.listen(8080);

and this doesn’t work.

All the suggested here dirty hacks cannot be used because it’s not universal for library with many users or add unnecessary complexity to configuration. Will check if we can solve this with AsyncLocalStorage, but in case if it’s not possible I’ll add this to the docs as a limitation of the underlying library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging with Pino and AsyncLocalStorage in Node.js
In this post, you can learn what a logging library is, why you should use it, and how to log with Pino and...
Read more >
7 Best Practices for C# Logging (With Examples)
To assign an output destination for your messages based on the logging level, create multiple appenders in your config file. For example, this...
Read more >
Node.js Logging with Winston
Introducing Node Js Developers to Logging Using Winston Loggers. ... The console module cannot perform many custom configurations.
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this list of the 10 most common JavaScript issues from a...
Read more >
Uncaught TypeError: Cannot assign to read only property
When you use Object.defineProperties , by default writable is set to false , so _year and edition are actually read only properties.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found