GithubHelp home page GithubHelp logo

Multithread-Capable MDC about scribe HOT 7 CLOSED

outr avatar outr commented on June 4, 2024
Multithread-Capable MDC

from scribe.

Comments (7)

darkfrog26 avatar darkfrog26 commented on June 4, 2024 2

Got tired of waiting. Released with 3.10.0

from scribe.

kell18 avatar kell18 commented on June 4, 2024

Hi! Thanks for the lib! As far as I can see it still will suffer from context switches? I.e. when a function executing in the future is getting moved to another execution thread? The MDC context for the function will not be preserved, right?

from scribe.

darkfrog26 avatar darkfrog26 commented on June 4, 2024

So, this was a bit of a half-measure. In order to share the context, you'd have to MDC.contextualize(mdc) { ... } in the block you want to utilize it. I'll give this some more thought on coming up with a better way to do it. If you have any thoughts, they would be welcome.

from scribe.

darkfrog26 avatar darkfrog26 commented on June 4, 2024

What would you think about me adding:

(implicit mdc: MDC = MDC.global)

to all logging calls and allow an implicit MDC to be able to be picked up?

from scribe.

kell18 avatar kell18 commented on June 4, 2024

Hmm, not many ideas from my side. But maybe it's not the task for the logging library if it was not initial design choice. I heard that it should be possible to do with custom ExecutionContexts but I never was able to make it working... https://blog.knoldus.com/how-to-use-mdc-logging-in-scala/

from scribe.

darkfrog26 avatar darkfrog26 commented on June 4, 2024

I've added some new functionality to allow the use of implicits:

    MDC { implicit mdc =>
      mdc("key") = "value"
      val f = Future {
        scribe.info("this is a test")
      }
      Await.result(f, Duration.Inf)
    }

The above will output with "key" = "value" in the logs. Would you say this adequately solves the problem? Of course, if you're working across multiple methods you'd have to pass around the implicit MDC.

from scribe.

darkfrog26 avatar darkfrog26 commented on June 4, 2024

@kell18 I'm planning to do a release this week, but I'd like confirmation that this update fulfills your needs?

from scribe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.