stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

Improve server-side logging options #264

Closed leastbad closed 3 years ago

leastbad commented 4 years ago

Feature Request

It would be nice if StimulusReflex offered better logging tooling that was comfortably in-between "way too verbose" and "totally suppressed".

Is your feature request related to a problem?

@marcoroth recently added amazing client-side logging, but we offer no SR-specific feedback unless there's literally an excpetion. This leads to lots of puts statements in Reflexes while debugging. We can do better!

Describe the solution you'd like

The ideal solution emits one tastefully colored line per Reflex action.

Some possible columns include:

ReflexClass#action eg. Example#hello Timestamp: eg. Time.now Round-trip execution time eg 8ms Session Identifier: eg. [215a1c85] Connection Identifier from AC channel: eg. leastbad Mode: eg. :selector Selector: eg. #notification Operation: eg. (selector: #notification)

Dream output

[215a1c85] Example#hello in 8ms (selector: #notification) for "leastbad" at 2020-07-07 15:04:13

... but in color.

Bonus points for being configurable via an initializer:

# config/initializers/stimulus_reflex.rb
StimulusReflex.configure do |config|
  # config.logging = :nil
  config.logging = [:session, :reflex, :benchmark, :operation, :identifier, :timestamp]
end

Additional context

The current options are two extremes: https://docs.stimulusreflex.com/troubleshooting#server-side

Adding an initializer is long overdue! Here's how:

  class << self
    mattr_accessor :logging
    self.logging = [] # this is the default, even if there is no initializer
  end

  def self.configure(&block)
    yield self
  end

Colors!

puts "\e[32mThis is green!"

puts "\e[1;32mThis is bright green!"

9UVnC

piotrwodz commented 3 years ago

@leastbad Recently I worked on a server-side logging per reflex action. As a result debugging in development feels more friendly ๐Ÿ‘ The guidelines defined in this issue were helpful. Thanks for that. There is a linked PR where you can find an overview of my solution. Give it a go, please! ๐ŸŽ๏ธ + ๐Ÿ‘€