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) ⇒ 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) ⇒ Text
Returns a new instance of Text.
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/neovim/logging.rb', line 114 def initialize file, color: nil, short: nil super @color = case color when true, false then color when 0 then false when Integer then true else @file.tty? end @short = short end |
Instance Method Details
#put(**fields) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/neovim/logging.rb', line 126 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 :class).to_s.sub /.*::/, ""), ((fields.map { |k,v| "#{k}:#{v}" }.join " ").axe 256), ] 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
152 153 154 155 156 157 158 159 |
# File 'lib/neovim/logging.rb', line 152 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 |