Module: NNQ::CLI::Term
- Defined in:
- lib/nnq/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.
Class Method Summary collapse
-
.format_attach(kind, url, verbose) ⇒ String
Formats an “attached endpoint” log line (Bound to / Connecting to).
-
.format_event(event, verbose) ⇒ String
Formats one NNQ::MonitorEvent into a single log line (no trailing newline).
-
.log_prefix(verbose) ⇒ String
Returns a stderr log line prefix.
-
.write_attach(kind, url, verbose, io: $stderr) ⇒ void
Writes one “Bound to / Connecting to” line to
io(default $stderr). -
.write_event(event, verbose, io: $stderr) ⇒ void
Writes one formatted event line to
io(default $stderr).
Class Method Details
.format_attach(kind, url, verbose) ⇒ String
Formats an “attached endpoint” log line (Bound to / Connecting to).
56 57 58 59 |
# File 'lib/nnq/cli/term.rb', line 56 def format_attach(kind, url, verbose) verb = kind == :bind ? "Bound to" : "Connecting to" "#{log_prefix(verbose)}nnq: #{verb} #{url}" end |
.format_event(event, verbose) ⇒ String
Formats one NNQ::MonitorEvent into a single log line (no trailing newline).
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nnq/cli/term.rb', line 35 def format_event(event, verbose) prefix = log_prefix(verbose) case event.type when :message_sent "#{prefix}nnq: >> #{Formatter.preview([event.detail[:body]])}" when :message_received "#{prefix}nnq: << #{Formatter.preview([event.detail[:body]])}" else ep = event.endpoint ? " #{event.endpoint}" : "" detail = event.detail ? " #{event.detail}" : "" "#{prefix}nnq: #{event.type}#{ep}#{detail}" end end |
.log_prefix(verbose) ⇒ String
Returns a stderr log line prefix. At verbose >= 4, prepends an ISO8601 UTC timestamp with µs precision so log traces become time-correlatable. Otherwise returns the empty string.
23 24 25 26 |
# File 'lib/nnq/cli/term.rb', line 23 def log_prefix(verbose) return "" unless verbose && verbose >= 4 "#{Time.now.utc.strftime("%FT%T.%6N")}Z " end |
.write_attach(kind, url, verbose, io: $stderr) ⇒ void
This method returns an undefined value.
Writes one “Bound to / Connecting to” line to io (default $stderr).
81 82 83 |
# File 'lib/nnq/cli/term.rb', line 81 def write_attach(kind, url, verbose, io: $stderr) io.write("#{format_attach(kind, url, verbose)}\n") end |
.write_event(event, verbose, io: $stderr) ⇒ void
This method returns an undefined value.
Writes one formatted event line to io (default $stderr).
68 69 70 |
# File 'lib/nnq/cli/term.rb', line 68 def write_event(event, verbose, io: $stderr) io.write("#{format_event(event, verbose)}\n") end |