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.
Accessed via Clack.log:
Class Method Summary collapse
-
.error(msg, output: $stdout) ⇒ void
Print an error message (red symbol).
-
.info(msg, output: $stdout) ⇒ void
Print an informational message (blue symbol).
-
.message(msg = "", symbol: nil, output: $stdout) ⇒ void
Print a message with a custom or default symbol prefix.
-
.step(msg, output: $stdout) ⇒ void
Print a step completion message (green submit symbol).
-
.success(msg, output: $stdout) ⇒ void
Print a success message (green symbol).
-
.warn(msg, output: $stdout) ⇒ void
(also: warning)
Print a warning message (yellow symbol).
Class Method Details
.error(msg, output: $stdout) ⇒ void
This method returns an undefined value.
Print an error message (red symbol).
88 89 90 |
# File 'lib/clack/log.rb', line 88 def error(msg, output: $stdout) (msg, symbol: Colors.red(Symbols::S_ERROR), output:) end |
.info(msg, output: $stdout) ⇒ void
This method returns an undefined value.
Print an informational message (blue symbol).
51 52 53 |
# File 'lib/clack/log.rb', line 51 def info(msg, output: $stdout) (msg, symbol: Colors.blue(Symbols::S_INFO), output:) end |
.message(msg = "", symbol: 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).
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/clack/log.rb', line 32 def (msg = "", symbol: nil, output: $stdout) symbol ||= Colors.gray(Symbols::S_BAR) lines = msg.to_s.lines if lines.empty? output.puts symbol else lines.each_with_index do |line, idx| prefix = idx.zero? ? symbol : Colors.gray(Symbols::S_BAR) output.puts "#{prefix} #{line.chomp}" end end end |
.step(msg, output: $stdout) ⇒ void
This method returns an undefined value.
Print a step completion message (green submit symbol).
69 70 71 |
# File 'lib/clack/log.rb', line 69 def step(msg, output: $stdout) (msg, symbol: Colors.green(Symbols::S_STEP_SUBMIT), output:) end |