Class: Overcommit::Logger
- Inherits:
-
Object
- Object
- Overcommit::Logger
- Defined in:
- lib/overcommit/logger.rb
Overview
Encapsulates all communication to an output source.
Class Method Summary collapse
-
.silent ⇒ Object
Helper for creating a logger which outputs nothing.
Instance Method Summary collapse
-
#bold(*args) ⇒ Object
Write a line of output that is intended to be emphasized.
-
#bold_error(*args) ⇒ Object
Write a line of output indicating a problem or error which is emphasized over a regular problem or error.
-
#bold_warning(*args) ⇒ Object
Write a line of output indicating a potential cause for concern, but with greater emphasize compared to other warnings.
-
#debug(*args) ⇒ Object
Write a line of output if debug mode is enabled.
-
#error(*args) ⇒ Object
Write a line of output indicating a problem or error.
-
#initialize(out) ⇒ Logger
constructor
Creates a logger that will write to the given output stream.
-
#log(*args) ⇒ Object
Write a line of output.
-
#newline ⇒ Object
Prints a newline character (alias for readability).
-
#partial(*args) ⇒ Object
Write output without a trailing newline.
-
#success(*args) ⇒ Object
Write a line of output indicating a successful or noteworthy event.
-
#warning(*args) ⇒ Object
Write a line of output indicating a potential cause for concern, but not an actual error.
Constructor Details
#initialize(out) ⇒ Logger
Creates a logger that will write to the given output stream.
12 13 14 |
# File 'lib/overcommit/logger.rb', line 12 def initialize(out) @out = out end |
Class Method Details
.silent ⇒ Object
Helper for creating a logger which outputs nothing.
5 6 7 |
# File 'lib/overcommit/logger.rb', line 5 def self.silent new(File.open(File::NULL, 'w')) end |
Instance Method Details
#bold(*args) ⇒ Object
Write a line of output that is intended to be emphasized.
39 40 41 |
# File 'lib/overcommit/logger.rb', line 39 def bold(*args) color('1', *args) end |
#bold_error(*args) ⇒ Object
Write a line of output indicating a problem or error which is emphasized over a regular problem or error.
50 51 52 |
# File 'lib/overcommit/logger.rb', line 50 def bold_error(*args) color('1;31', *args) end |
#bold_warning(*args) ⇒ Object
Write a line of output indicating a potential cause for concern, but with greater emphasize compared to other warnings.
67 68 69 |
# File 'lib/overcommit/logger.rb', line 67 def bold_warning(*args) color('1;33', *args) end |
#debug(*args) ⇒ Object
Write a line of output if debug mode is enabled.
34 35 36 |
# File 'lib/overcommit/logger.rb', line 34 def debug(*args) color('35', *args) unless ENV.fetch('OVERCOMMIT_DEBUG', '').empty? end |
#error(*args) ⇒ Object
Write a line of output indicating a problem or error.
44 45 46 |
# File 'lib/overcommit/logger.rb', line 44 def error(*args) color(31, *args) end |
#log(*args) ⇒ Object
Write a line of output.
A newline character will always be appended.
29 30 31 |
# File 'lib/overcommit/logger.rb', line 29 def log(*args) @out.puts(*args) end |
#newline ⇒ Object
Prints a newline character (alias for readability).
22 23 24 |
# File 'lib/overcommit/logger.rb', line 22 def newline log end |
#partial(*args) ⇒ Object
Write output without a trailing newline.
17 18 19 |
# File 'lib/overcommit/logger.rb', line 17 def partial(*args) @out.print(*args) end |
#success(*args) ⇒ Object
Write a line of output indicating a successful or noteworthy event.
55 56 57 |
# File 'lib/overcommit/logger.rb', line 55 def success(*args) color(32, *args) end |
#warning(*args) ⇒ Object
Write a line of output indicating a potential cause for concern, but not an actual error.
61 62 63 |
# File 'lib/overcommit/logger.rb', line 61 def warning(*args) color(33, *args) end |