Class: Neovim::Logging::Text
- Defined in:
- lib/neovim/logging.rb
Constant Summary collapse
- NAME =
"file"
- COLORS =
%w(33 32 34;1 4 31;1 35;1 36)
Constants inherited from Logger
Instance Method Summary collapse
-
#initialize(file, color: nil, short: nil, maxlen: 256) ⇒ Text
constructor
A new instance of Text.
- #put(**fields) ⇒ Object
- #put_sep ⇒ Object
Methods inherited from Stream
Methods inherited from Logger
Constructor Details
#initialize(file, color: nil, short: nil, maxlen: 256) ⇒ Text
Returns a new instance of Text.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/neovim/logging.rb', line 123 def initialize file, color: nil, short: nil, maxlen: 256 super @color = case color when true, false then color when 0 then false when Integer then true else @file.tty? end @short, @maxlen = short, maxlen end |
Instance Method Details
#put(**fields) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/neovim/logging.rb', line 135 def put **fields put_sep l = [ ((fields.delete :time).strftime "%H:%M:%S"), ((fields.delete :pid).to_s.rjust 5), (fields.delete :caller).to_s[ %r([^/]+:\d+)], (fields.delete :level), (fields.delete :message).inspect, (fields.delete :sender).class_name, ((fields.map { |k,v| "#{k}:#{v}" }.join " ").axe @maxlen), ] if @color then l = l.zip COLORS l.map! do |f,c| "\e[#{c}m#{f}\e[m" end end if @short then s = l.shift 3 if not @nexttime or @nexttime < Time.now then @file.puts s.join " " @nexttime = Time.now + 120 end end @file.puts l.join " " @file.flush nil end |
#put_sep ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/neovim/logging.rb', line 161 def put_sep if @file.tty? then if not @nextsep or @nextsep < Time.now then @file.puts $/*5 @nextsep = Time.now + 300 end end end |