|
20 | 20 | require 'monitor' |
21 | 21 | require 'logger' |
22 | 22 | require 'json' |
| 23 | +require 'base64' |
| 24 | +require 'securerandom' |
23 | 25 |
|
24 | 26 | module Fluent |
25 | 27 | module Logger |
@@ -98,14 +100,16 @@ def last_error |
98 | 100 | def post_with_time(tag, map, time) |
99 | 101 | @logger.debug { "event: #{tag} #{map.to_json}" rescue nil } if @logger.debug? |
100 | 102 | tag = "#{@tag_prefix}.#{tag}" if @tag_prefix |
101 | | - write [tag, time.to_i, map] |
| 103 | + write(tag, time.to_i, map) |
102 | 104 | end |
103 | 105 |
|
104 | 106 | def close |
105 | 107 | @mon.synchronize { |
106 | 108 | if @pending |
107 | 109 | begin |
108 | | - send_data(@pending) |
| 110 | + @pending.each do |tag, record| |
| 111 | + send_data([tag, record].to_msgpack) |
| 112 | + end |
109 | 113 | rescue => e |
110 | 114 | set_last_error(e) |
111 | 115 | @logger.error("FluentLogger: Can't send logs to #{connection_string}: #{$!}") |
@@ -153,36 +157,40 @@ def suppress_sec |
153 | 157 | end |
154 | 158 | end |
155 | 159 |
|
156 | | - def write(msg) |
| 160 | + def write(tag, time, map) |
157 | 161 | begin |
158 | | - data = to_msgpack(msg) |
| 162 | + record = to_msgpack([time, map]) |
159 | 163 | rescue => e |
160 | 164 | set_last_error(e) |
| 165 | + msg = [tag, time, map] |
161 | 166 | @logger.error("FluentLogger: Can't convert to msgpack: #{msg.inspect}: #{$!}") |
162 | 167 | return false |
163 | 168 | end |
164 | 169 |
|
165 | 170 | @mon.synchronize { |
166 | 171 | if @pending |
167 | | - @pending << data |
| 172 | + @pending[tag] << record |
168 | 173 | else |
169 | | - @pending = data |
| 174 | + @pending = Hash.new{|h, k| h[k] = "" } |
| 175 | + @pending[tag] = record |
170 | 176 | end |
171 | 177 |
|
172 | 178 | # suppress reconnection burst |
173 | | - if !@connect_error_history.empty? && @pending.bytesize <= @limit |
| 179 | + if !@connect_error_history.empty? && @pending.to_s.bytesize <= @limit |
174 | 180 | if Time.now.to_i - @connect_error_history.last < suppress_sec |
175 | 181 | return false |
176 | 182 | end |
177 | 183 | end |
178 | 184 |
|
179 | 185 | begin |
180 | | - send_data(@pending) |
| 186 | + @pending.each do |tag, record| |
| 187 | + send_data([tag, record].to_msgpack) |
| 188 | + end |
181 | 189 | @pending = nil |
182 | 190 | true |
183 | 191 | rescue => e |
184 | 192 | set_last_error(e) |
185 | | - if @pending.bytesize > @limit |
| 193 | + if @pending.to_s.bytesize > @limit |
186 | 194 | @logger.error("FluentLogger: Can't send logs to #{connection_string}: #{$!}") |
187 | 195 | call_buffer_overflow_handler(@pending) |
188 | 196 | @pending = nil |
@@ -212,6 +220,7 @@ def send_data(data) |
212 | 220 | # end |
213 | 221 | # data = data[n..-1] |
214 | 222 | #end |
| 223 | + |
215 | 224 | true |
216 | 225 | end |
217 | 226 |
|
|
0 commit comments