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: nil, start_at: Terminal.start_at!, **options) ⇒ Logger
constructor
A new instance of Logger.
- #register_defaults(terminal) ⇒ Object
- #verbose!(value = true) ⇒ Object
Constructor Details
#initialize(io = $stderr, verbose: nil, start_at: Terminal.start_at!, **options) ⇒ Logger
Returns a new instance of Logger.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/console/terminal/logger.rb', line 55 def initialize(io = $stderr, verbose: nil, start_at: Terminal.start_at!, **) @io = io @start_at = start_at @terminal = Terminal.for(io) if verbose.nil? @verbose = !@terminal.colors? else @verbose = verbose end @terminal[:logger_prefix] ||= @terminal.style(nil, nil, nil) @terminal[:logger_suffix] ||= @terminal.style(:white, nil, :faint) @terminal[:subject] ||= @terminal.style(nil, nil, :bold) @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.
79 80 81 |
# File 'lib/console/terminal/logger.rb', line 79 def io @io end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
81 82 83 |
# File 'lib/console/terminal/logger.rb', line 81 def start @start end |
#terminal ⇒ Object (readonly)
Returns the value of attribute terminal.
82 83 84 |
# File 'lib/console/terminal/logger.rb', line 82 def terminal @terminal end |
#verbose ⇒ Object
Returns the value of attribute verbose.
80 81 82 |
# File 'lib/console/terminal/logger.rb', line 80 def verbose @verbose end |
Instance Method Details
#call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/console/terminal/logger.rb', line 97 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
88 89 90 91 92 93 |
# File 'lib/console/terminal/logger.rb', line 88 def register_defaults(terminal) Event.constants.each do |constant| klass = Event.const_get(constant) klass.register(terminal) end end |
#verbose!(value = true) ⇒ Object
84 85 86 |
# File 'lib/console/terminal/logger.rb', line 84 def verbose!(value = true) @verbose = value end |