Class: Mbeditor::CableLogFilter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/mbeditor/cable_log_filter.rb

Overview

Wraps the ActionCable logger and suppresses all log lines that mention Mbeditor channels so the development console stays readable. Non-Mbeditor ActionCable messages pass through unchanged.

Defined Under Namespace

Classes: UntaggedFormatter

Constant Summary collapse

SUPPRESS_PATTERN =
/Mbeditor::|mbeditor_editor/
CABLE_WEBSOCKET_REQUEST_PATTERN =
/(?:Started|Finished) "\/cable(?:\/[^\"]*)?" \[WebSocket\]/

Instance Method Summary collapse

Instance Method Details

#clear_tags!Object



103
104
105
106
107
# File 'lib/mbeditor/cable_log_filter.rb', line 103

def clear_tags!
  return __getobj__.clear_tags! if __getobj__.respond_to?(:clear_tags!)

  nil
end

#current_tagsObject

Rails/ActiveSupport logger compatibility. Some logger stacks call these methods even when the underlying logger is not TaggedLogging.



85
86
87
88
89
# File 'lib/mbeditor/cable_log_filter.rb', line 85

def current_tags
  return __getobj__.current_tags if __getobj__.respond_to?(:current_tags)

  []
end

#flushObject



109
110
111
112
# File 'lib/mbeditor/cable_log_filter.rb', line 109

def flush
  clear_tags!
  __getobj__.flush if __getobj__.respond_to?(:flush)
end

#formatterObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mbeditor/cable_log_filter.rb', line 39

def formatter
  underlying_formatter = resolve_formatter

  return underlying_formatter if underlying_formatter.respond_to?(:current_tags)

  if defined?(@untagged_formatter_source) && @untagged_formatter_source.equal?(underlying_formatter)
    return @untagged_formatter
  end

  @untagged_formatter_source = underlying_formatter
  @untagged_formatter = UntaggedFormatter.new(underlying_formatter)
end

#pop_tags(count = 1) ⇒ Object



97
98
99
100
101
# File 'lib/mbeditor/cable_log_filter.rb', line 97

def pop_tags(count = 1)
  return __getobj__.pop_tags(count) if __getobj__.respond_to?(:pop_tags)

  []
end

#push_tags(*tags) ⇒ Object



91
92
93
94
95
# File 'lib/mbeditor/cable_log_filter.rb', line 91

def push_tags(*tags)
  return __getobj__.push_tags(*tags) if __getobj__.respond_to?(:push_tags)

  tags
end

#resolve_formatterObject



52
53
54
55
56
# File 'lib/mbeditor/cable_log_filter.rb', line 52

def resolve_formatter
  return Logger::Formatter.new unless __getobj__.respond_to?(:formatter)

  __getobj__.formatter || Logger::Formatter.new
end

#suppress_message?(message) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/mbeditor/cable_log_filter.rb', line 67

def suppress_message?(message)
  message.match?(SUPPRESS_PATTERN) || message.match?(CABLE_WEBSOCKET_REQUEST_PATTERN)
end

#tagged(*tags, &block) ⇒ Object

Tagged-logging compat — the block body still passes through the filter.



72
73
74
75
76
77
78
79
80
81
# File 'lib/mbeditor/cable_log_filter.rb', line 72

def tagged(*tags, &block)
  if __getobj__.respond_to?(:tagged)
    tagged_logger = __getobj__.tagged(*tags, &block)
    block ? tagged_logger : self.class.new(tagged_logger)
  elsif block
    block.call
  else
    self
  end
end