Class: SCSSLint::Logger
- Inherits:
-
Object
- Object
- SCSSLint::Logger
- Defined in:
- lib/scss_lint/logger.rb
Overview
Encapsulates all communication to an output source.
Instance Attribute Summary collapse
-
#color_enabled ⇒ true, false
Whether colored output via ANSI escape sequences is enabled.
Class Method Summary collapse
-
.silent ⇒ SCSSLint::Logger
Creates a logger which outputs nothing.
Instance Method Summary collapse
-
#bold(output) ⇒ Object
Mark the specified output in bold face.
-
#bold_error(output, newline = true) ⇒ Object
Print the specified output in a bold face and color indicative of error.
-
#bold_red(output) ⇒ Object
Mark the specified output in bold red.
-
#cyan(output) ⇒ Object
Mark the specified output in cyan.
-
#error(output, newline = true) ⇒ Object
Print the specified output in a color indicative of error.
-
#green(output) ⇒ Object
Mark the specified output in green.
-
#info(output, newline = true) ⇒ Object
Print the specified output in a color indicating information.
-
#initialize(out) ⇒ Logger
constructor
Creates a new Logger instance.
-
#log(output, newline = true) ⇒ Object
Print the specified output.
-
#magenta(output) ⇒ Object
Mark the specified output in magenta.
-
#newline ⇒ Object
Print a blank line.
-
#red(output) ⇒ Object
Mark the specified output in red.
-
#success(output, newline = true) ⇒ Object
Print the specified output in a color indicative of success.
-
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
-
#warning(output, newline = true) ⇒ Object
Print the specified output in a color indicative of a warning.
-
#yellow(output) ⇒ Object
Mark the specified output in yellow.
Constructor Details
#initialize(out) ⇒ Logger
Creates a new SCSSLint::Logger instance.
17 18 19 |
# File 'lib/scss_lint/logger.rb', line 17 def initialize(out) @out = out end |
Instance Attribute Details
#color_enabled ⇒ true, false
Whether colored output via ANSI escape sequences is enabled.
6 7 8 |
# File 'lib/scss_lint/logger.rb', line 6 def color_enabled @color_enabled end |
Class Method Details
.silent ⇒ SCSSLint::Logger
Creates a logger which outputs nothing.
10 11 12 |
# File 'lib/scss_lint/logger.rb', line 10 def self.silent new(File.open('/dev/null', 'w')) end |
Instance Method Details
#bold(output) ⇒ Object
Mark the specified output in bold face. If output destination is not a TTY, this is a noop.
84 85 86 |
# File 'lib/scss_lint/logger.rb', line 84 def bold(output) color('1', output) end |
#bold_error(output, newline = true) ⇒ Object
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.
44 45 46 |
# File 'lib/scss_lint/logger.rb', line 44 def bold_error(output, newline = true) log(bold_red(output), newline) end |
#bold_red(output) ⇒ Object
Mark the specified output in bold red. If output destination is not a TTY, this is a noop.
92 93 94 |
# File 'lib/scss_lint/logger.rb', line 92 def bold_red(output) color('1;31', output) end |
#cyan(output) ⇒ Object
Mark the specified output in cyan. If output destination is not a TTY, this is a noop.
132 133 134 |
# File 'lib/scss_lint/logger.rb', line 132 def cyan(output) color(36, output) end |
#error(output, newline = true) ⇒ Object
Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as #log.
35 36 37 |
# File 'lib/scss_lint/logger.rb', line 35 def error(output, newline = true) log(red(output), newline) end |
#green(output) ⇒ Object
Mark the specified output in green. If output destination is not a TTY, this is a noop.
108 109 110 |
# File 'lib/scss_lint/logger.rb', line 108 def green(output) color(32, output) end |
#info(output, newline = true) ⇒ Object
Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as #log.
71 72 73 |
# File 'lib/scss_lint/logger.rb', line 71 def info(output, newline = true) log(cyan(output), newline) end |
#log(output, newline = true) ⇒ Object
Print the specified output.
25 26 27 28 |
# File 'lib/scss_lint/logger.rb', line 25 def log(output, newline = true) @out.print(output) @out.print("\n") if newline end |
#magenta(output) ⇒ Object
Mark the specified output in magenta. If output destination is not a TTY, this is a noop.
124 125 126 |
# File 'lib/scss_lint/logger.rb', line 124 def magenta(output) color(35, output) end |
#newline ⇒ Object
Print a blank line.
76 77 78 |
# File 'lib/scss_lint/logger.rb', line 76 def newline log('') end |
#red(output) ⇒ Object
Mark the specified output in red. If output destination is not a TTY, this is a noop.
100 101 102 |
# File 'lib/scss_lint/logger.rb', line 100 def red(output) color(31, output) end |
#success(output, newline = true) ⇒ Object
Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as #log.
53 54 55 |
# File 'lib/scss_lint/logger.rb', line 53 def success(output, newline = true) log(green(output), newline) end |
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
139 140 141 |
# File 'lib/scss_lint/logger.rb', line 139 def tty? @out.respond_to?(:tty?) && @out.tty? end |
#warning(output, newline = true) ⇒ Object
Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.
62 63 64 |
# File 'lib/scss_lint/logger.rb', line 62 def warning(output, newline = true) log(yellow(output), newline) end |
#yellow(output) ⇒ Object
Mark the specified output in yellow. If output destination is not a TTY, this is a noop.
116 117 118 |
# File 'lib/scss_lint/logger.rb', line 116 def yellow(output) color(33, output) end |