Class: Phlex::Reactive::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/phlex/reactive/log_subscriber.rb

Overview

Opt-in LogSubscriber (issue #107): turns each hot-path event into ONE compact debug line, so a developer can watch reactive traffic in the log without an APM:

[reactive] Counter#increment ok (3.1ms)
[reactive] Counter#drop_table denied_undeclared (0.2ms)
[reactive] render Counter 512B (0.9ms)
[reactive] broadcast replace Counter →2 (1.4ms)

Default OFF — the events fire for APMs regardless of this; attaching the subscriber only adds the gem's own log lines. The engine attaches it once at boot when Phlex::Reactive.log_events is true. Lines are logged at DEBUG, so they're invisible unless the app's log level allows it.

Payloads carry NAMES/outcome/sizes ONLY (never token/params/state), so these lines can never leak a secret. A :invalid_token event has no trusted component name (the token didn't verify), so the line omits the Class# prefix rather than echo an unverified class.

Instance Method Summary collapse

Instance Method Details

#action(event) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/phlex/reactive/log_subscriber.rb', line 26

def action(event)
  return unless logger.debug?

  payload = event.payload
  subject =
    if payload[:component]
      "#{payload[:component]}##{payload[:action]}"
    else
      # No trusted component (invalid token) — name the action alone.
      payload[:action]
    end
  debug { "[reactive] #{subject} #{payload[:outcome]} (#{round(event.duration)}ms)" }
end

#broadcast(event) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/phlex/reactive/log_subscriber.rb', line 47

def broadcast(event)
  return unless logger.debug?

  payload = event.payload
  debug do
    "[reactive] broadcast #{payload[:stream_action]} #{payload[:component]} " \
      "#{payload[:streamables]} (#{round(event.duration)}ms)"
  end
end

#defer(event) ⇒ Object

The defer endpoint / render leg (issue #165). Like #action, an :invalid_token event carries no TRUSTED component name — omit it.



59
60
61
62
63
64
65
# File 'lib/phlex/reactive/log_subscriber.rb', line 59

def defer(event)
  return unless logger.debug?

  payload = event.payload
  subject = [payload[:component], payload[:outcome]].compact.join(" ")
  debug { "[reactive] defer #{subject} (#{round(event.duration)}ms)" }
end

#render(event) ⇒ Object



40
41
42
43
44
45
# File 'lib/phlex/reactive/log_subscriber.rb', line 40

def render(event)
  return unless logger.debug?

  payload = event.payload
  debug { "[reactive] render #{payload[:component]} #{payload[:bytesize]}B (#{round(event.duration)}ms)" }
end