Class: Bauxite::Loggers::TerminalLogger
- Inherits:
-
NullLogger
- Object
- NullLogger
- Bauxite::Loggers::TerminalLogger
- Defined in:
- lib/bauxite/loggers/terminal.rb
Overview
Terminal logger.
This logger outputs text using basic text formatting for a terminal window.
Direct Known Subclasses
Instance Method Summary collapse
-
#debug_prompt ⇒ Object
Returns a colorized debug prompt.
-
#initialize(options) ⇒ TerminalLogger
constructor
Constructs a new Terminal logger instance.
-
#log(s, type = :info) ⇒ Object
Prints the specified string.
-
#log_cmd(action) ⇒ Object
Pretty prints action information and status.
-
#progress(value) ⇒ Object
Updates action progress.
Methods inherited from NullLogger
Constructor Details
#initialize(options) ⇒ TerminalLogger
Constructs a new Terminal logger instance.
30 31 32 33 |
# File 'lib/bauxite/loggers/terminal.rb', line 30 def initialize() super() @max_cmd_size = Bauxite::Context::max_action_name_size end |
Instance Method Details
#debug_prompt ⇒ Object
Returns a colorized debug prompt.
69 70 71 |
# File 'lib/bauxite/loggers/terminal.rb', line 69 def debug_prompt _fmt(:white, super) end |
#log(s, type = :info) ⇒ Object
Prints the specified string.
See Bauxite::Loggers::NullLogger#print
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bauxite/loggers/terminal.rb', line 85 def log(s, type = :info) color = :gray case type when :error color = :red when :warning color = :yellow when :debug color = :purple end super _fmt(color, s), type end |
#log_cmd(action) ⇒ Object
Pretty prints action information and status.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bauxite/loggers/terminal.rb', line 36 def log_cmd(action) width = _screen_width cmd = action.cmd.downcase color = _cmd_color(cmd) cmd = cmd.ljust(@max_cmd_size) max_args_size = width-cmd.size-1-6-1-1 print "#{_fmt(color, cmd)} " s = action.args(true).join(' ') s = s[0...max_args_size-3]+'...' if s.size > max_args_size print s.ljust(max_args_size) $stdout.flush _save_cursor color = :green text = 'OK' ret = yield if not ret color = :yellow text = 'SKIP' end _restore_cursor puts " #{_block(color, text, 5)}" $stdout.flush ret rescue _restore_cursor puts " #{_block(:red, 'ERROR', 5)}" $stdout.flush raise end |
#progress(value) ⇒ Object
Updates action progress.
74 75 76 77 78 79 |
# File 'lib/bauxite/loggers/terminal.rb', line 74 def progress(value) if _restore_cursor print " #{_block(:gray, value.to_s, 5)}" $stdout.flush end end |