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.

[3.0.0-rc3] Logging object with circular references breaking

See original GitHub issue

v3.0.0-rc3

When logging data with circular data, it does not log and subsequent logs are not logged neither

      const customData = {};
      customData.myself = customData; // circular data

      const logger = winston.createLogger({ transports: [new winston.transports.Console()] });
      logger.info('hello'); // shows on console

      logger.error({
        message: 'testing error',
        myCustomData: customData,
      }); // doesn't log

      logger.info('hello'); // doesn't log

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
indexzerocommented, Apr 6, 2018

@crussell52 @Nokel81 @danlevan removing built-in, default always on support for logging of circular object references was a conscious performance decision for the default winston behavior in winston@3.

This problem is 100% solvable as a custom format – here’s a quick & dirty one. If you’d like to contribute one to logform (like circular-json or perhaps a { circular: true } option that users must opt-in to) that would be neat.

const cycle = require('cycle');
const { format } = require('winston');
const { combine, json } = format;

// Create a format to decycle the object
const decycleFormat = format((info, opts) => cycle.decycle(info))

// Combine the decycleFormat with the built-in json format.
const circularJsonFormat = combine(
  decycle(),
  json()
);
2reactions
crussell52commented, Apr 5, 2018

… and subsequent logs are not logged neither

This may be arguable the more important point – I ran into a case where a formatter threw an exception and all subsequent log attempts quietly failed. An edge-case failure in logging a message should not halt all logging 😟

Is that expected behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging object with circular reference with Mongo Appender ...
I've blogged some days ago on the possibility to save log4net logs inside a Mongo database, but you should be aware that this...
Read more >
Detecting and fixing circular references in JavaScript
Here is MDN's approach to detecting and fixing circular references when using JSON.stringify() on circular objects: ...
Read more >
Remove or allow a circular reference - Microsoft Support
The formula =D1+D2+D3 breaks because it lives in cell D3, and it's trying to calculate itself. To fix the problem, you can move...
Read more >
Circular Dependencies in Dependency Injection - Medium
A description of how we solved a circular dependency in our dependency injection, and some of the software principles involved.
Read more >
code quality - What's wrong with circular references?
Circular object references also make dependency injection impossible, significantly reducing the testability of your system. Objects with a very ...
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