Module: OMQ::CLI::Term
- Defined in:
- lib/omq/cli/term.rb
Overview
Stateless terminal formatting and stderr writing helpers shared by every code path that emits verbose-driven log lines (event monitor callbacks in BaseRunner / PipeRunner, SocketSetup attach helpers, parallel/pipe Ractor workers).
Pure module functions: no state, no instance, safe to call from any thread or Ractor. Errors and abort messages do not go through this module — they aren’t logs.
Class Method Summary collapse
-
.format_attach(kind, url, timestamps) ⇒ String
Formats an “attached endpoint” log line (bound to / connecting to).
-
.format_event(event, timestamps) ⇒ String
Formats one OMQ::MonitorEvent into a single log line (no trailing newline).
-
.format_event_detail(detail) ⇒ String
Renders MonitorEvent#detail as a “ (…)” suffix for log lines.
-
.log_prefix(timestamps) ⇒ String
Returns a stderr log line prefix with a UTC ISO8601 timestamp at the requested precision (:s/:ms/:us), or “” when nil.
-
.write_attach(kind, url, timestamps, io: $stderr) ⇒ void
Writes one “bound to / connecting to” line to
io(default $stderr). -
.write_event(event, timestamps, io: $stderr) ⇒ void
Writes one formatted event line to
io(default $stderr).
Class Method Details
.format_attach(kind, url, timestamps) ⇒ String
Formats an “attached endpoint” log line (bound to / connecting to).
90 91 92 93 |
# File 'lib/omq/cli/term.rb', line 90 def format_attach(kind, url, ) verb = kind == :bind ? "bound to" : "connecting to" "#{log_prefix()}omq: #{verb} #{url}" end |
.format_event(event, timestamps) ⇒ String
Formats one OMQ::MonitorEvent into a single log line (no trailing newline).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/omq/cli/term.rb', line 39 def format_event(event, ) prefix = log_prefix() case event.type when :message_sent "#{prefix}omq: >> #{Formatter.preview(event.detail[:parts], wire_size: event.detail[:wire_size])}" when :message_received "#{prefix}omq: << #{Formatter.preview(event.detail[:parts], wire_size: event.detail[:wire_size])}" when :zdict_sent "#{prefix}omq: >> ZDICT (#{event.detail[:size]}B)" when :zdict_received "#{prefix}omq: << ZDICT (#{event.detail[:size]}B)" else ep = event.endpoint ? " #{event.endpoint}" : "" detail = format_event_detail(event.detail) "#{prefix}omq: #{event.type}#{ep}#{detail}" end end |
.format_event_detail(detail) ⇒ String
Renders MonitorEvent#detail as a “ (…)” suffix for log lines. Rewrites plain peer-close exceptions (EOFError) to “closed by peer” — the io-stream library reports these as “Stream finished before reading enough data!”, which is confusing noise for what is just a normal disconnect.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/omq/cli/term.rb', line 66 def format_event_detail(detail) return "" if detail.nil? return " #{detail}" unless detail.is_a?(Hash) error = detail[:error] reason = detail[:reason] case error when nil reason ? " (#{reason})" : "" when EOFError " (closed by peer)" else " (#{reason || error.})" end end |
.log_prefix(timestamps) ⇒ String
Returns a stderr log line prefix with a UTC ISO8601 timestamp at the requested precision (:s/:ms/:us), or “” when nil.
23 24 25 26 27 28 29 30 |
# File 'lib/omq/cli/term.rb', line 23 def log_prefix() case when nil then "" when :s then "#{Time.now.utc.strftime("%FT%T")}Z " when :ms then "#{Time.now.utc.strftime("%FT%T.%3N")}Z " when :us then "#{Time.now.utc.strftime("%FT%T.%6N")}Z " end end |
.write_attach(kind, url, timestamps, io: $stderr) ⇒ void
This method returns an undefined value.
Writes one “bound to / connecting to” line to io (default $stderr).
115 116 117 |
# File 'lib/omq/cli/term.rb', line 115 def write_attach(kind, url, , io: $stderr) io.write("#{format_attach(kind, url, )}\n") end |
.write_event(event, timestamps, io: $stderr) ⇒ void
This method returns an undefined value.
Writes one formatted event line to io (default $stderr).
102 103 104 |
# File 'lib/omq/cli/term.rb', line 102 def write_event(event, , io: $stderr) io.write("#{format_event(event, )}\n") end |