guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.91k stars 245 forks source link

Replace Kernel warnings with Listen.logger #574

Closed AlexB52 closed 4 months ago

AlexB52 commented 7 months ago

Fix #572

In case we can move these calls to Listen.logger here is the PR for the change.

ColinDKelley commented 4 months ago

@AlexB52 I'm concerned that log warnings will almost never be seen. That's why Kernel.warn or Kernel#warn was being called--so that these warnings would be visible. But clearly there are cases where people don't want to see one or more of the warnings.

I wonder if instead the warnings could be configurable in listen? Maybe there could be a proc that could be registered that would get to look at each warning and decide whether to show it or not?

AlexB52 commented 4 months ago

@ColinDKelley Not sure I understand the registration proc. Is your idea of a proc like this? What is the preferred way to make this globally available? Can you provide some pseudocode to illustrate the idea please?

warn = ->(message) {
  return if ENV['LISTEN_GEM_DISABLE_WARNING'].present?

  Kernel.warn(message)
}

What about a Listen::Warning class that calls Kernel.warn unless a ENV variable LISTEN_GEM_DISABLE_WARNING is set. That would make it a bit more explicit maybe?

Something like:

module Listen
  class Warning
    module_function
    def warn(message)
      return if ENV['LISTEN_GEM_DISABLE_WARNING'].present?

      Kernel.warn(message)
    end
  end
end