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:

Examples:

Clack.log.info("Starting build...")
Clack.log.success("Build completed!")
Clack.log.warn("Cache is stale")
Clack.log.error("Build failed")

Class Method Summary collapse

Class Method Details

.error(msg, output: $stdout) ⇒ void

This method returns an undefined value.

Print an error message (red symbol).

Parameters:

  • msg (String)

    the message to display

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



88
89
90
# File 'lib/clack/log.rb', line 88

def error(msg, output: $stdout)
  message(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).

Parameters:

  • msg (String)

    the message to display

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



51
52
53
# File 'lib/clack/log.rb', line 51

def info(msg, output: $stdout)
  message(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).

Examples:

Custom symbol

Clack.log.message("Deploying...", symbol: "\u2708")

Parameters:

  • msg (String) (defaults to: "")

    the message to display

  • symbol (String, nil) (defaults to: nil)

    custom prefix symbol (default: gray bar)

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/clack/log.rb', line 32

def message(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).

Parameters:

  • msg (String)

    the message to display

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



69
70
71
# File 'lib/clack/log.rb', line 69

def step(msg, output: $stdout)
  message(msg, symbol: Colors.green(Symbols::S_STEP_SUBMIT), output:)
end

.success(msg, output: $stdout) ⇒ void

This method returns an undefined value.

Print a success message (green symbol).

Parameters:

  • msg (String)

    the message to display

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



60
61
62
# File 'lib/clack/log.rb', line 60

def success(msg, output: $stdout)
  message(msg, symbol: Colors.green(Symbols::S_SUCCESS), output:)
end

.warn(msg, output: $stdout) ⇒ void Also known as: warning

This method returns an undefined value.

Print a warning message (yellow symbol).

Parameters:

  • msg (String)

    the message to display

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



78
79
80
# File 'lib/clack/log.rb', line 78

def warn(msg, output: $stdout)
  message(msg, symbol: Colors.yellow(Symbols::S_WARN), output:)
end