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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6036171c770b0e463648f39628bcd9d2a30743cd
4
- data.tar.gz: d322a415e1e35afb854aa37127dc516a92df54c6
3
+ metadata.gz: 1a993ade5fab4fe045bf09545478b9cdc23bad7a
4
+ data.tar.gz: e1e1f78e26f30630ebea95fe9a33ee8dff17896c
5
5
  SHA512:
6
- metadata.gz: 8cc5da6687684e04fab3d08af413ba04f21265c9b0730eb766f045d458d1d56894ddb7805c50f94f33d856f0c70e6d8a4de2498668760bb935f917c47581db0d
7
- data.tar.gz: ce3f294646541532435d88d7d6b32a208456d8f3af60c705a91f8ab9c85a6293ea71bb0bd8e30db611afb69acf33fd6ba92a2e6ffc115fbdd729148e214e90ea
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
- @lines = []
132
- @recording = true
133
- @status = nil
134
- @time_taken = nil
135
- @url = request.fullpath
136
- Rails.logger = ActionController::Base.logger = ActiveRecord::Base.logger = self
137
- instrumenter = ActiveSupport::Notifications.instrumenter
138
- instrumenter.start "request.action_dispatch", request: request
139
- logger.info { started_request_message(request) }
140
- status, headers, response = @app.call(env)
141
- finish(request, response)
142
- [status, headers, response]
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
- if send_request?(request)
178
- unless body.is_a?(String)
179
- body = body.to_a rescue [body.body]
180
- end
191
+ unless body.is_a?(String)
192
+ body = body.to_a rescue [body.body]
193
+ end
181
194
 
182
- if body.respond_to?(:each)
183
- @output = []
184
- body.each do |line|
185
- @output << line
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
- if @influxdb.nil?
193
- puts @log
194
- return
195
- end
205
+ if @influxdb.nil?
206
+ puts @log
207
+ return
208
+ end
196
209
 
197
- @log ||= "None found"
198
- @output ||= "None found"
210
+ @log ||= "None found"
211
+ @output ||= "None found"
212
+ @status ||= "-"
199
213
 
200
- data = {
201
- values: { log: @log[0, 65535], output: @output, output_length: @output.length, status: @status || "-", ms_taken: @time_taken.to_i},
202
- tags: { url: request.fullpath, method: request.request_method, app: app_name },
203
- timestamp: (Time.now.to_r * 1000).to_i
204
- }
205
- data[:values][:email] = request.headers["X-CivoCom-User-Email"] if request.headers["X-CivoCom-User-Email"].present?
206
- data[:values][:civocom_request_path] = request.headers["X-CivoCom-Request-Path"] if request.headers["X-CivoCom-Request-Path"].present?
207
- data[:tags][:civocom_request_id] = request.headers["X-CivoCom-RequestID"] if request.headers["X-CivoCom-RequestID"].present?
208
- data[:tags][:request_id] = request.uuid if request.uuid.present?
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
- @influxdb.write_point("requests", data, INFLUXDB_PRECISION)# , INFLUXDB_RETENTION)
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
 
@@ -1,5 +1,5 @@
1
1
  module Civo
2
2
  module Logger
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.5"
4
4
  end
5
5
  end
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
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-09 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb