class HamlLint::Logger

Encapsulates all communication to an output source.

Attributes

color_enabled[RW]

Whether colored output via ANSI escape sequences is enabled. @return [true,false]

summary_enabled[RW]

Whether to output a summary in the log for certain reporters. @return [true,false]

Public Class Methods

new(out, summary: true) click to toggle source

Creates a new {HamlLint::Logger} instance.

@param out [IO] the output destination. @param summary [true,false] whether to print summaries

# File lib/haml_lint/logger.rb, line 23
def initialize(out, summary: true)
  @out = out
  @summary_enabled = summary
end
silent() click to toggle source

Creates a logger which outputs nothing. @return [HamlLint::Logger]

# File lib/haml_lint/logger.rb, line 15
def self.silent
  new(File.open('/dev/null', 'w'))
end

Public Instance Methods

bold(*args) click to toggle source

Print the specified output in bold face. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 41
def bold(*args)
  color('1', *args)
end
bold_error(*args) click to toggle source

Print the specified output in a bold face and color indicative of error. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 57
def bold_error(*args)
  color('1;31', *args)
end
error(*args) click to toggle source

Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 49
def error(*args)
  color(31, *args)
end
info(*args) click to toggle source

Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 81
def info(*args)
  color(36, *args)
end
log(output, newline = true) click to toggle source

Print the specified output.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/haml_lint/logger.rb, line 32
def log(output, newline = true)
  @out.print(output)
  @out.print("\n") if newline
end
newline() click to toggle source

Print a blank line.

# File lib/haml_lint/logger.rb, line 86
def newline
  log('')
end
success(*args) click to toggle source

Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 65
def success(*args)
  color(32, *args)
end
tty?() click to toggle source

Whether this logger is outputting to a TTY.

@return [true,false]

# File lib/haml_lint/logger.rb, line 93
def tty?
  @out.respond_to?(:tty?) && @out.tty?
end
warning(*args) click to toggle source

Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as {#log}.

@param args [Array<String>]

# File lib/haml_lint/logger.rb, line 73
def warning(*args)
  color(33, *args)
end

Private Instance Methods

color(code, output, newline = true) click to toggle source
# File lib/haml_lint/logger.rb, line 99
def color(code, output, newline = true)
  log(color_enabled ? "\033[#{code}m#{output}\033[0m" : output, newline)
end