|
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 #{@host}:#{@port}: #{$!}") |
@@ -140,36 +144,40 @@ def suppress_sec |
140 | 144 | end |
141 | 145 | end |
142 | 146 |
|
143 | | - def write(msg) |
| 147 | + def write(tag, time, map) |
144 | 148 | begin |
145 | | - data = to_msgpack(msg) |
| 149 | + record = to_msgpack([time, map]) |
146 | 150 | rescue => e |
147 | 151 | set_last_error(e) |
| 152 | + msg = [tag, time, map] |
148 | 153 | @logger.error("FluentLogger: Can't convert to msgpack: #{msg.inspect}: #{$!}") |
149 | 154 | return false |
150 | 155 | end |
151 | 156 |
|
152 | 157 | @mon.synchronize { |
153 | 158 | if @pending |
154 | | - @pending << data |
| 159 | + @pending[tag] << record |
155 | 160 | else |
156 | | - @pending = data |
| 161 | + @pending = Hash.new{|h, k| h[k] = "" } |
| 162 | + @pending[tag] = record |
157 | 163 | end |
158 | 164 |
|
159 | 165 | # suppress reconnection burst |
160 | | - if !@connect_error_history.empty? && @pending.bytesize <= @limit |
| 166 | + if !@connect_error_history.empty? && @pending.to_s.bytesize <= @limit |
161 | 167 | if Time.now.to_i - @connect_error_history.last < suppress_sec |
162 | 168 | return false |
163 | 169 | end |
164 | 170 | end |
165 | 171 |
|
166 | 172 | begin |
167 | | - send_data(@pending) |
| 173 | + @pending.each do |tag, record| |
| 174 | + send_data([tag, record].to_msgpack) |
| 175 | + end |
168 | 176 | @pending = nil |
169 | 177 | true |
170 | 178 | rescue => e |
171 | 179 | set_last_error(e) |
172 | | - if @pending.bytesize > @limit |
| 180 | + if @pending.to_s.bytesize > @limit |
173 | 181 | @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}") |
174 | 182 | call_buffer_overflow_handler(@pending) |
175 | 183 | @pending = nil |
@@ -199,6 +207,7 @@ def send_data(data) |
199 | 207 | # end |
200 | 208 | # data = data[n..-1] |
201 | 209 | #end |
| 210 | + |
202 | 211 | true |
203 | 212 | end |
204 | 213 |
|
|
0 commit comments