civo-logger 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/civo/logger/middleware.rb +60 -42
- data/lib/civo/logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a993ade5fab4fe045bf09545478b9cdc23bad7a
|
4
|
+
data.tar.gz: e1e1f78e26f30630ebea95fe9a33ee8dff17896c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed8c32275a085192fcdeb002f5f96b8662cf7b833c0fe3537ad073d46d7c57aa3f6bc1b6d2eab1db965b68cda3002496cc59d9be1cd2a2981d383b87afa147e0
|
7
|
+
data.tar.gz: 591e06334c320bc85779a46276d885f966a4a8bab317d5989ddaba61c5ecc9a58c1114bd80df0d4760b64b7cf90cdc48ebd2cd538a7e041c38eb280b00d3632b
|
@@ -125,23 +125,37 @@ module Civo
|
|
125
125
|
@recording = false
|
126
126
|
end
|
127
127
|
|
128
|
+
def silence
|
129
|
+
yield self
|
130
|
+
end
|
131
|
+
|
128
132
|
private
|
129
133
|
|
130
134
|
def call_app(request, env) # :doc:
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
if send_request?(request)
|
136
|
+
puts "In send request"
|
137
|
+
@lines = []
|
138
|
+
@recording = true
|
139
|
+
@status = nil
|
140
|
+
@time_taken = nil
|
141
|
+
@url = request.fullpath
|
142
|
+
Rails.logger = ActionController::Base.logger = ActiveRecord::Base.logger = self
|
143
|
+
instrumenter = ActiveSupport::Notifications.instrumenter
|
144
|
+
instrumenter.start "request.action_dispatch", request: request
|
145
|
+
logger.info { started_request_message(request) }
|
146
|
+
status, headers, response = @app.call(env)
|
147
|
+
@status = status.to_s
|
148
|
+
finish(request, response)
|
149
|
+
[status, headers, response]
|
150
|
+
else
|
151
|
+
Rails.logger = ActionController::Base.logger = ActiveRecord::Base.logger = self
|
152
|
+
instrumenter = ActiveSupport::Notifications.instrumenter
|
153
|
+
instrumenter.start "request.action_dispatch", request: request
|
154
|
+
logger.info { started_request_message(request) }
|
155
|
+
@app.call(env)
|
156
|
+
end
|
143
157
|
rescue Exception => e
|
144
|
-
finish(request, e.message)
|
158
|
+
finish(request, [e.message])
|
145
159
|
raise
|
146
160
|
ensure
|
147
161
|
ActiveSupport::LogSubscriber.flush_all!
|
@@ -174,41 +188,40 @@ module Civo
|
|
174
188
|
instrumenter.finish "request.action_dispatch", request: request
|
175
189
|
@log = @lines.join("\n")
|
176
190
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
191
|
+
unless body.is_a?(String)
|
192
|
+
body = body.to_a rescue [body.body]
|
193
|
+
end
|
181
194
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
187
|
-
@output = @output.join("\n")
|
188
|
-
else
|
189
|
-
@output = body.to_s
|
195
|
+
if body.respond_to?(:each)
|
196
|
+
@output = []
|
197
|
+
body.each do |line|
|
198
|
+
@output << line
|
190
199
|
end
|
200
|
+
@output = @output.join("\n")
|
201
|
+
else
|
202
|
+
@output = body.to_s
|
203
|
+
end
|
191
204
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
205
|
+
if @influxdb.nil?
|
206
|
+
puts @log
|
207
|
+
return
|
208
|
+
end
|
196
209
|
|
197
|
-
|
198
|
-
|
210
|
+
@log ||= "None found"
|
211
|
+
@output ||= "None found"
|
212
|
+
@status ||= "-"
|
199
213
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
214
|
+
data = {
|
215
|
+
values: { log: @log[0, 65535], output: @output, output_length: @output.length, status: @status, ms_taken: @time_taken.to_i},
|
216
|
+
tags: { url: request.fullpath, method: request.request_method, app: app_name },
|
217
|
+
timestamp: (Time.now.to_r * 1000).to_i
|
218
|
+
}
|
219
|
+
data[:values][:email] = request.headers["X-CivoCom-User-Email"] if request.headers["X-CivoCom-User-Email"].present?
|
220
|
+
data[:values][:civocom_request_path] = request.headers["X-CivoCom-Request-Path"] if request.headers["X-CivoCom-Request-Path"].present?
|
221
|
+
data[:tags][:civocom_request_id] = request.headers["X-CivoCom-RequestID"] if request.headers["X-CivoCom-RequestID"].present?
|
222
|
+
data[:tags][:request_id] = request.uuid if request.uuid.present?
|
209
223
|
|
210
|
-
|
211
|
-
end
|
224
|
+
@influxdb.write_point("requests", data, INFLUXDB_PRECISION)# , INFLUXDB_RETENTION)
|
212
225
|
|
213
226
|
if Rails.env.development? || Rails.env.test?
|
214
227
|
File.open("#{Rails.root}/log/#{Rails.env}.log", "a") do |f|
|
@@ -223,14 +236,19 @@ module Civo
|
|
223
236
|
end
|
224
237
|
|
225
238
|
def send_request?(request)
|
239
|
+
puts request.fullpath
|
226
240
|
if request.fullpath["/resque"]
|
227
241
|
return false
|
228
242
|
elsif request.fullpath["/civostatsd"]
|
229
243
|
return false
|
244
|
+
elsif request.fullpath["/assets"]
|
245
|
+
puts "Returning false"
|
246
|
+
return false
|
230
247
|
elsif request.fullpath["/ping"]
|
231
248
|
return false
|
232
249
|
end
|
233
250
|
|
251
|
+
puts "Returning true"
|
234
252
|
true
|
235
253
|
end
|
236
254
|
|
data/lib/civo/logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civo-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: influxdb
|