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

NDC Support #130

Closed
ghost opened this issue Apr 19, 2013 · 8 comments
Closed

NDC Support #130

ghost opened this issue Apr 19, 2013 · 8 comments
Projects
Milestone

Comments

@ghost
Copy link

ghost commented Apr 19, 2013

Hi,

Are there plans to support nested diagnostic contexts?

@nomiddlename
Copy link
Collaborator

No plans at the moment, but I'm happy to accept pull requests for it. Not sure how it would work though, seeing as NDC in log4j (java) was meant for multi-threaded environments and node is single-threaded. Any ideas?

@nomiddlename
Copy link
Collaborator

There's this library, which may do what you want: https://github.com/majorleaguesoccer/stacklog

@blalor
Copy link

blalor commented Jul 28, 2013

I would also like to see NDC (or MDC) support of some kind. I initially thinking I'd just hack something together by using unique logger categories, but if you create a logger per connection, the logger instances are leaked because log4js keeps a reference to them. I'll look into stacklog, but I'll need to verify that it doesn't cause the same problem.

@nomiddlename
Copy link
Collaborator

nomiddlename commented Mar 27, 2017

Something like this will be possible in version 2.x - a logger can have context added to it, which will be added to all log events that use that logger. Also log4js no longer keeps references to loggers. The only appender that makes use of the context is the logFaces one at the moment though.

@nomiddlename nomiddlename added this to the 2.x milestone Mar 27, 2017
@nomiddlename nomiddlename added this to TODO in Version 2.x Mar 27, 2017
@jorgemsrs
Copy link
Contributor

jorgemsrs commented Jun 15, 2017

I have a patch to land MDC support for the 1.x branch. Would it be something you would be willing to accept?
My patch adds support to patternLayout with %X{} as defined in https://logback.qos.ch/manual/mdc.html
Given that the 2.x branch is being developed in master how should I proceed with the PR?

@nomiddlename
Copy link
Collaborator

You should be able to make the same changes to pattern layout in 2.x - the 2.x Logger has support for a context that works much the same as the MDC in that article. Each logEvent will get a copy of the context when it is created. The logFaces appenders make use of the values, so that should give you an example of how to access the fields. I'd rather the feature was added to 2.x - I'm planning to release it to npm very soon (just got a performance problem to look into).

Thanks for looking into this, by the way - I'm grateful for any help. If it really has to be included in 1.x for you (perhaps waiting and then upgrading is not an option), let me know and we can work something out.

@jorgemsrs
Copy link
Contributor

I can wait for the new release :)
Adapted the patch to fit into master. Please have a look.

Thanks

@nomiddlename nomiddlename moved this from TODO to Done in Version 2.x Jun 18, 2017
@nomiddlename
Copy link
Collaborator

Released in version 2.0.0

lamweili added a commit to lamweili/log4js-node that referenced this issue Feb 2, 2021
Backported features for log4js:

     feat: add line number, column position and filename support
     log4js-node@5da824e

     feat(log4js-node#130): Add support for MDC in pattern layout
     log4js-node@6e15364

     feat: add delimiter for fileName depth to %f layout patern
     log4js-node@e70d132
lamweili added a commit to lamweili/log4js-node that referenced this issue Feb 2, 2021
Backported features for log4js:

     feat: add line number, column position and filename support
     log4js-node/log4js-node@5da824e

     feat(log4js-node#130): Add support for MDC in pattern layout
     log4js-node/log4js-node@6e15364

     feat: add delimiter for fileName depth to %f layout patern
     log4js-node/log4js-node@e70d132
lamweili added a commit to lamweili/log4js-node that referenced this issue Feb 2, 2021
Backported features for log4js:

     feat: add line number, column position and filename support
     log4js-node/log4js-node@5da824e

     feat(log4js-node#130): Add support for MDC in pattern layout
     log4js-node/log4js-node@6e15364

     feat: add delimiter for fileName depth to %f layout patern
     log4js-node/log4js-node@e70d132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants