class SCSSLint::Logger
Encapsulates all communication to an output source.
Attributes
Whether colored output via ANSI escape sequences is enabled. @return [true,false]
Public Class Methods
Creates a new {SCSSLint::Logger} instance.
@param out [IO] the output destination.
# File lib/scss_lint/logger.rb, line 17 def initialize(out) @out = out end
Creates a logger which outputs nothing. @return [SCSSLint::Logger]
# File lib/scss_lint/logger.rb, line 10 def self.silent new(File.open('/dev/null', 'w')) end
Public Instance Methods
Mark the specified output in bold face. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 84 def bold(output) color('1', output) end
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 output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 44 def bold_error(output, newline = true) log(bold_red(output), newline) end
Mark the specified output in bold red. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 92 def bold_red(output) color('1;31', output) end
Mark the specified output in cyan. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 132 def cyan(output) color(36, output) end
Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as {#log}.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 35 def error(output, newline = true) log(red(output), newline) end
Mark the specified output in green. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 108 def green(output) color(32, output) end
Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as {#log}.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 71 def info(output, newline = true) log(cyan(output), newline) end
Print the specified output.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 25 def log(output, newline = true) @out.print(output) @out.print("\n") if newline end
Mark the specified output in magenta. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 124 def magenta(output) color(35, output) end
Print a blank line.
# File lib/scss_lint/logger.rb, line 76 def newline log('') end
Mark the specified output in red. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 100 def red(output) color(31, output) end
Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as {#log}.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 53 def success(output, newline = true) log(green(output), newline) end
Whether this logger is outputting to a TTY.
@return [true,false]
# File lib/scss_lint/logger.rb, line 139 def tty? @out.respond_to?(:tty?) && @out.tty? end
Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as {#log}.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/scss_lint/logger.rb, line 62 def warning(output, newline = true) log(yellow(output), newline) end
Mark the specified output in yellow. If output destination is not a TTY, this is a noop.
@param output [String] the output to format
# File lib/scss_lint/logger.rb, line 116 def yellow(output) color(33, output) end
Private Instance Methods
# File lib/scss_lint/logger.rb, line 145 def color(code, output) color_enabled ? "\033[#{code}m#{output}\033[0m" : output end