Class: HamlLint::Logger
- Inherits:
-
Object
- Object
- HamlLint::Logger
- Defined in:
- lib/haml_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.
-
#summary_enabled ⇒ true, false
Whether to output a summary in the log for certain reporters.
Class Method Summary collapse
-
.silent ⇒ HamlLint::Logger
Creates a logger which outputs nothing.
Instance Method Summary collapse
-
#bold(*args) ⇒ Object
Print the specified output in bold face.
-
#bold_error(*args) ⇒ Object
Print the specified output in a bold face and color indicative of error.
-
#error(*args) ⇒ Object
Print the specified output in a color indicative of error.
-
#info(*args) ⇒ Object
Print the specified output in a color indicating information.
-
#initialize(out, summary: true) ⇒ Logger
constructor
Creates a new Logger instance.
-
#log(output, newline = true) ⇒ Object
Print the specified output.
-
#newline ⇒ Object
Print a blank line.
-
#success(*args) ⇒ Object
Print the specified output in a color indicative of success.
-
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
-
#warning(*args) ⇒ Object
Print the specified output in a color indicative of a warning.
Constructor Details
#initialize(out, summary: true) ⇒ Logger
Creates a new HamlLint::Logger instance.
22 23 24 25 |
# File 'lib/haml_lint/logger.rb', line 22 def initialize(out, summary: true) @out = out @summary_enabled = summary end |
Instance Attribute Details
#color_enabled ⇒ true, false
Whether colored output via ANSI escape sequences is enabled.
6 7 8 |
# File 'lib/haml_lint/logger.rb', line 6 def color_enabled @color_enabled end |
#summary_enabled ⇒ true, false
Whether to output a summary in the log for certain reporters.
10 11 12 |
# File 'lib/haml_lint/logger.rb', line 10 def summary_enabled @summary_enabled end |
Class Method Details
.silent ⇒ HamlLint::Logger
Creates a logger which outputs nothing.
14 15 16 |
# File 'lib/haml_lint/logger.rb', line 14 def self.silent new(File.open('/dev/null', 'w')) end |
Instance Method Details
#bold(*args) ⇒ Object
Print the specified output in bold face. If output destination is not a TTY, behaves the same as #log.
40 41 42 |
# File 'lib/haml_lint/logger.rb', line 40 def bold(*args) color('1', *args) end |
#bold_error(*args) ⇒ 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.
56 57 58 |
# File 'lib/haml_lint/logger.rb', line 56 def bold_error(*args) color('1;31', *args) end |
#error(*args) ⇒ Object
Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as #log.
48 49 50 |
# File 'lib/haml_lint/logger.rb', line 48 def error(*args) color(31, *args) end |
#info(*args) ⇒ Object
Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as #log.
80 81 82 |
# File 'lib/haml_lint/logger.rb', line 80 def info(*args) color(36, *args) end |
#log(output, newline = true) ⇒ Object
Print the specified output.
31 32 33 34 |
# File 'lib/haml_lint/logger.rb', line 31 def log(output, newline = true) @out.print(output) @out.print("\n") if newline end |
#newline ⇒ Object
Print a blank line.
85 86 87 |
# File 'lib/haml_lint/logger.rb', line 85 def newline log('') end |
#success(*args) ⇒ Object
Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as #log.
64 65 66 |
# File 'lib/haml_lint/logger.rb', line 64 def success(*args) color(32, *args) end |
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
92 93 94 |
# File 'lib/haml_lint/logger.rb', line 92 def tty? @out.respond_to?(:tty?) && @out.tty? end |
#warning(*args) ⇒ Object
Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.
72 73 74 |
# File 'lib/haml_lint/logger.rb', line 72 def warning(*args) color(33, *args) end |