Module: Clack::Log
- Defined in:
- lib/clack/log.rb
Overview
Styled console logging with consistent formatting.
Each method prints a message prefixed with a colored symbol. Multi-line messages are automatically aligned with a continuation bar on subsequent lines.
With guides off (+with_guide: false+ or Clack.update_settings(with_guide: false))
the level symbol stays on the first line and only the continuation rail goes
away, so log.error still looks different from log.info (upstream drops the
symbol as well).
Accessed via Clack.log:
Class Method Summary collapse
-
.error(msg, with_guide: nil, output: $stdout) ⇒ void
Print an error message (red symbol).
-
.info(msg, with_guide: nil, output: $stdout) ⇒ void
Print an informational message (blue symbol).
-
.message(msg = "", symbol: nil, with_guide: nil, output: $stdout) ⇒ void
Print a message with a custom or default symbol prefix.
-
.step(msg, with_guide: nil, output: $stdout) ⇒ void
Print a step completion message (green submit symbol).
-
.success(msg, with_guide: nil, output: $stdout) ⇒ void
Print a success message (green symbol).
-
.warn(msg, with_guide: nil, output: $stdout) ⇒ void
(also: warning)
Print a warning message (yellow symbol).
Class Method Details
.error(msg, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Print an error message (red symbol).
102 103 104 |
# File 'lib/clack/log.rb', line 102 def error(msg, with_guide: nil, output: $stdout) (msg, symbol: Colors.red(Symbols::S_ERROR), with_guide:, output:) end |
.info(msg, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Print an informational message (blue symbol).
61 62 63 |
# File 'lib/clack/log.rb', line 61 def info(msg, with_guide: nil, output: $stdout) (msg, symbol: Colors.blue(Symbols::S_INFO), with_guide:, output:) end |
.message(msg = "", symbol: nil, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Print a message with a custom or default symbol prefix.
This is the base method used by all other log methods. Pass symbol:
to customize the leading character (useful for extending with your own
log levels).
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/clack/log.rb', line 38 def (msg = "", symbol: nil, with_guide: nil, output: $stdout) guide = Core::Settings.with_guide?(with_guide) rail = Colors.gray(Symbols::S_BAR) first = symbol || (guide ? rail : nil) first_prefix = first ? "#{first} " : "" next_prefix = guide ? "#{rail} " : "" lines = msg.to_s.lines if lines.empty? output.puts first.to_s else lines.each_with_index do |line, idx| output.puts "#{idx.zero? ? first_prefix : next_prefix}#{line.chomp}" end end end |
.step(msg, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Print a step completion message (green submit symbol).
81 82 83 |
# File 'lib/clack/log.rb', line 81 def step(msg, with_guide: nil, output: $stdout) (msg, symbol: Colors.green(Symbols::S_STEP_SUBMIT), with_guide:, output:) end |
.success(msg, with_guide: nil, output: $stdout) ⇒ void
This method returns an undefined value.
Print a success message (green symbol).
71 72 73 |
# File 'lib/clack/log.rb', line 71 def success(msg, with_guide: nil, output: $stdout) (msg, symbol: Colors.green(Symbols::S_SUCCESS), with_guide:, output:) end |
.warn(msg, with_guide: nil, output: $stdout) ⇒ void Also known as: warning
This method returns an undefined value.
Print a warning message (yellow symbol).
91 92 93 |
# File 'lib/clack/log.rb', line 91 def warn(msg, with_guide: nil, output: $stdout) (msg, symbol: Colors.yellow(Symbols::S_WARN), with_guide:, output:) end |