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.

Combine child metadata with additional metadata

See original GitHub issue

I’m not sure this is a bug or feature request. I’ll use the bug template since it also contains the behavior I’d expect.

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v12.14.0
  • Operating System? (Windows, macOS, or Linux) Linux
  • Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart) ES6/7

What is the problem?

There seems to be no way to combine child metadata with additional properties. In fact, I find the multiple api signatures in which one can log a message to be quite conflicting/confusing. For example, consider this code:

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.printf(({ message, prefix}) => `[${prefix}]: ${message}`),
  defaultMeta: { prefix: 'root' },
  transports: [new winston.transports.Console()],
});

logger.info('foo 1', { foo: 'bar' });
logger.log('info','foo 2');
logger.log('info','foo 3', {});
logger.log({ level: 'info', message: 'foo 4' });

const childLogger = logger.child({ prefix: 'child' });
childLogger.info('foo 5', { foo: 'bar' });
childLogger.log('info','foo 6');
childLogger.log('info','foo 7', {});
childLogger.log({ level: 'info', message: 'foo 8' });

All of these are valid, but produce different/unexpected results:

[root]: foo 1
[undefined]: foo 2
[root]: foo 3
[root]: foo 4
[root]: foo 5
[child]: foo 6
[root]: foo 7
[root]: foo 8

What do you expect to happen instead?

I can’t really find an api reference, so it’s hard to know what is to be expected and what not. But I would expect that when I create a child logger with metadata, the metadata acts in the way the default metadata on the logger works. Because now, there is no way to add in additional properties in a log call, without losing the metadata passed in to the child logger.

So I would expect that I can still call childLogger.log('info', 'message', { additionalProp: 'foo' }) and still have the prefix=child property in the metadata. And in fact, I would expect this to be the case for any of the example calls to childLogger.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
traceoncommented, Jan 13, 2021

@aressler38 I took a more radical and seemingly consistent approach in #1879. Reused your test though.

0reactions
maverick1872commented, Jan 14, 2022

Closing as this issue is being consolidated into #2029

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to find all the related Child Objects metadata - standard ...
You can create custom metadata to store all required standard object names. In your logic read that custom metadata and parse the value...
Read more >
Metadata API allows duplicate child relationship names
When creating custom fields via the metadata API using CRUD, Salesforce will erroneously allow creating a lookup field with a duplicate child relationship ......
Read more >
Combining metadata with folders in SharePoint
This post explains how it works, and why this option doesn't work in the File Explorer view of a synced library. A typical...
Read more >
Using the Metadata Merge Utility
If you are upgrading to a new release from an existing release, you can use the Metadata Merge utility to merge your existing...
Read more >
Metadata API Developer Guide
API. Other Use Cases. You can use Metadata API for larger changes in Salesforce, such as splitting and merging production orgs.
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