Class: Console::Terminal::Logger
- Inherits:
-
Object
- Object
- Console::Terminal::Logger
- Defined in:
- lib/console/terminal/logger.rb
Constant Summary collapse
- UNKNOWN =
'unknown'
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#terminal ⇒ Object
readonly
Returns the value of attribute terminal.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block) ⇒ Object
-
#initialize(io = $stderr, verbose: false, **options) ⇒ Logger
constructor
A new instance of Logger.
- #register_defaults(terminal) ⇒ Object
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize(io = $stderr, verbose: false, **options) ⇒ Logger
Returns a new instance of Logger.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/console/terminal/logger.rb', line 40 def initialize(io = $stderr, verbose: false, **) @io = io @verbose = verbose @start = Time.now @terminal = Terminal.for(io) @terminal[:logger_prefix] ||= @terminal.style(nil, nil, :bold) @terminal[:logger_suffix] ||= @terminal.style(:white, nil, :faint) @terminal[:debug] = @terminal.style(:cyan) @terminal[:info] = @terminal.style(:green) @terminal[:warn] = @terminal.style(:yellow) @terminal[:error] = @terminal.style(:red) @terminal[:fatal] = @terminal[:error] self.register_defaults(@terminal) end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
57 58 59 |
# File 'lib/console/terminal/logger.rb', line 57 def io @io end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
59 60 61 |
# File 'lib/console/terminal/logger.rb', line 59 def start @start end |
#terminal ⇒ Object (readonly)
Returns the value of attribute terminal.
60 61 62 |
# File 'lib/console/terminal/logger.rb', line 60 def terminal @terminal end |
#verbose ⇒ Object
Returns the value of attribute verbose.
58 59 60 |
# File 'lib/console/terminal/logger.rb', line 58 def verbose @verbose end |
Instance Method Details
#call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/console/terminal/logger.rb', line 73 def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block) prefix = build_prefix(name || severity.to_s) indent = " " * prefix.size buffer = Buffer.new("#{indent}| ") if subject format_subject(severity, prefix, subject, buffer) end arguments.each do |argument| format_argument(argument, buffer) end if block_given? if block.arity.zero? format_argument(yield, buffer) else yield(buffer, @terminal) end end @io.write buffer.string end |
#register_defaults(terminal) ⇒ Object
66 67 68 69 |
# File 'lib/console/terminal/logger.rb', line 66 def register_defaults(terminal) Shell.register(terminal) Error.register(terminal) end |
#verbose!(value = true) ⇒ Object
62 63 64 |
# File 'lib/console/terminal/logger.rb', line 62 def verbose!(value = true) @verbose = value end |