ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.71k stars 420 forks source link

Best way to override logger on a per-promise basis? #867

Closed thbar closed 4 years ago

thbar commented 4 years ago

Thanks for your work on concurrent-ruby!

I discovered through experimentation that:

Concurrent::Promises.future { raise Exception }

will log automatically on STDOUT (but will not log if you raise a StandardError).

Is there a recommended way to override that on a per-future fashion?

I see that setting @logger should normally be the road to follow (https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/concern/logging.rb), but it is not working so far.

Before diving into that more (and especially since https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/configuration.rb has various comments on deadlocks etc!), is there a recommended way to override that without going global?

The rationale behind this is that I'm creating a reusable component using concurrent-ruby, and it could end up being used in a Rails app already using concurrent-ruby in its own way, so isolating one logging strategy from another would be useful.

Thanks for your input!

thbar commented 4 years ago

I can live without that for now, and don't want to clutter the current maintainers, so I will close for now. If I investigate more later, I will comment back!