akita-har_logger 0.2.10 → 0.2.14

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
  SHA256:
3
- metadata.gz: 26fd1b1b5e2ccf962928f85e6969b50f63766571f40cf442cf5b615bb44559e9
4
- data.tar.gz: b6e0ef99924d4b9db81fa0c0981cdc84d41e11930493843c110bc595bdee9447
3
+ metadata.gz: 9eed2465cdafed5eb9d0af31022054193efdcd6ba8b2866a466c51554e24ab43
4
+ data.tar.gz: 4553cd54a99c9d1a2958657e90b31deeb40e237d508bbd1b80c9cbc59064ef64
5
5
  SHA512:
6
- metadata.gz: c4953346d8f0f2169aea261ebab4768e3868cfbd0511c0d276791b06b6c2e5871f5d054b869b2d3fed0c99eb5d3cad7712bf7a9dd15d2698052da5e22ff3d756
7
- data.tar.gz: bc46a89f9eeea951a20e34ed9a2bab0c9dee5fd7a8e5ed996d2fe06942d917279345bae0e12c662a0423baff927790dde4c82a99baf834537615deb1d62b796e
6
+ metadata.gz: 04ff7a6f33614994d7bc82d4fb52b5b3957be1f405df36316330dd811d7949968325eaf997276d775e85f1df17461c4733cebdae9eeef6fb0bd4be53f309cdb0
7
+ data.tar.gz: f0325184bc764d7eba84573d164bed1c676300cfac8f27b63dafea6f0ebafe80dd58cacc965c694830355c603a7a23b6c2435b3a1b92c22be89093c06869cc0e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- akita-har_logger (0.2.10)
4
+ akita-har_logger (0.2.14)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,6 +33,9 @@ module Akita
33
33
  end
34
34
 
35
35
  @entry_queue = HarLogger.get_queue(out_file_name)
36
+ rescue => e
37
+ HarLogger.logException("initializing middleware", e)
38
+ raise
36
39
  end
37
40
 
38
41
  def call(env)
@@ -59,9 +62,21 @@ module Akita
59
62
  env['rack.input'] = saved_input
60
63
 
61
64
  [ status, headers, body ]
65
+ rescue => e
66
+ HarLogger.logException("handling request", e)
67
+ raise
62
68
  end
63
69
  end
64
70
 
71
+ # Logs the given exception.
72
+ def self.logException(context, e)
73
+ Rails.logger.debug "AKITA: Exception while #{context}: #{e.message} "\
74
+ "(#{e.class.name}) in thread #{Thread.current}"
75
+ e.backtrace.each { |frame|
76
+ Rails.logger.debug "AKITA: #{frame}"
77
+ }
78
+ end
79
+
65
80
  # Logging filter for `ActionController`s.
66
81
  # TODO: Some amount of code duplication here. Should refactor.
67
82
  class Filter
@@ -71,6 +86,9 @@ module Akita
71
86
  end
72
87
 
73
88
  @entry_queue = HarLogger.get_queue(out_file_name)
89
+ rescue => e
90
+ HarLogger.logException("initializing filter", e)
91
+ raise
74
92
  end
75
93
 
76
94
  # Registers an `on_load` initializer to add a logging filter to any
@@ -108,6 +126,9 @@ module Akita
108
126
 
109
127
  # Be kind and restore the original request-body stream.
110
128
  request.env['rack.input'] = saved_input
129
+ rescue => e
130
+ HarLogger.logException("handling request", e)
131
+ raise
111
132
  end
112
133
  end
113
134
 
@@ -128,13 +149,23 @@ module Akita
128
149
  # queue.
129
150
  def self.get_queue(out_file_name)
130
151
  queue = nil
152
+ Rails.logger.debug "AKITA: About to acquire entry-queue mutex "\
153
+ "#{@@entry_queues_mutex} in #{Thread.current}. "\
154
+ "Self-owned? #{@@entry_queues_mutex.owned?}"
131
155
  @@entry_queues_mutex.synchronize {
132
- if @@entry_queues.has_key?(out_file_name) then
133
- return @@entry_queues[out_file_name]
156
+ begin
157
+ Rails.logger.debug "AKITA: Acquired entry-queue mutex "\
158
+ "#{@@entry_queues_mutex} in #{Thread.current}."
159
+ if @@entry_queues.has_key?(out_file_name) then
160
+ return @@entry_queues[out_file_name]
161
+ end
162
+
163
+ queue = Queue.new
164
+ @@entry_queues[out_file_name] = queue
165
+ ensure
166
+ Rails.logger.debug "AKITA: About to release entry-queue mutex "\
167
+ "#{@@entry_queues_mutex} in #{Thread.current}."
134
168
  end
135
-
136
- queue = Queue.new
137
- @@entry_queues[out_file_name] = queue
138
169
  }
139
170
 
140
171
  WriterThread.new out_file_name, queue
@@ -159,7 +159,9 @@ module Akita
159
159
 
160
160
  def getBodySize(body)
161
161
  length = 0
162
- body.each { |part| length += part.bytesize }
162
+ # Convert each body part into a string in case we're dealing with
163
+ # non-Rack-compliant components.
164
+ body.each { |part| length += part.to_s.bytesize }
163
165
  length
164
166
  end
165
167
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Akita
4
4
  module HarLogger
5
- VERSION = "0.2.10"
5
+ VERSION = "0.2.14"
6
6
  end
7
7
  end
@@ -15,42 +15,57 @@ module Akita
15
15
  shutdown_mutex = Mutex.new
16
16
 
17
17
  Thread.new do
18
+ Rails.logger.debug "AKITA: About to acquire shutdown mutex "\
19
+ "#{shutdown_mutex} for file #{out_file_name} "\
20
+ "in writer thread #{Thread.current}. "\
21
+ "Self-owned? #{shutdown_mutex.owned?}"
18
22
  shutdown_mutex.synchronize {
19
- File.open(out_file_name, 'w') { |f|
20
- # Produce a preamble.
21
- f.write <<~EOF.chomp
22
- {
23
- "log": {
24
- "version": "1.2",
25
- "creator": {
26
- "name": "Akita HAR logger for Ruby",
27
- "version": "1.0.0"
28
- },
29
- "entries": [
30
- EOF
23
+ begin
24
+ Rails.logger.debug "AKITA: Acquired shutdown mutex "\
25
+ "#{shutdown_mutex} for file "\
26
+ "#{out_file_name} in writer thread "\
27
+ "#{Thread.current}."
28
+ File.open(out_file_name, 'w') { |f|
29
+ # Produce a preamble.
30
+ f.write <<~EOF.chomp
31
+ {
32
+ "log": {
33
+ "version": "1.2",
34
+ "creator": {
35
+ "name": "Akita HAR logger for Ruby",
36
+ "version": "1.0.0"
37
+ },
38
+ "entries": [
39
+ EOF
31
40
 
32
- first_entry = true
41
+ first_entry = true
33
42
 
34
- loop do
35
- entry = entry_queue.pop
36
- if entry == nil then break end
43
+ loop do
44
+ entry = entry_queue.pop
45
+ if entry == nil then break end
37
46
 
38
- # Emit comma separator if needed.
39
- f.puts (first_entry ? '' : ',')
40
- first_entry = false
47
+ # Emit comma separator if needed.
48
+ f.puts (first_entry ? '' : ',')
49
+ first_entry = false
41
50
 
42
- # Emit the dequeued entry.
43
- f.write JSON.generate(entry)
44
- end
51
+ # Emit the dequeued entry.
52
+ f.write JSON.generate(entry)
53
+ end
45
54
 
46
- # Produce the epilogue.
47
- f.write <<~EOF
55
+ # Produce the epilogue.
56
+ f.write <<~EOF
48
57
 
49
- ]
58
+ ]
59
+ }
50
60
  }
51
- }
52
- EOF
53
- }
61
+ EOF
62
+ }
63
+ ensure
64
+ Rails.logger.debug "AKITA: About to release shutdown mutex "\
65
+ "#{shutdown_mutex} for file "\
66
+ "#{out_file_name} in writer thread "\
67
+ "#{Thread.current}."
68
+ end
54
69
  }
55
70
  end
56
71
 
@@ -59,7 +74,18 @@ module Akita
59
74
  # Signal to the consumer that this is the end of the entry stream and
60
75
  # wait for the consumer to terminate.
61
76
  entry_queue << nil
62
- shutdown_mutex.synchronize {}
77
+ Rails.logger.debug "AKITA: About to acquire shutdown mutex "\
78
+ "#{shutdown_mutex} for file #{out_file_name} "\
79
+ "while shutting down in #{Thread.current}. "\
80
+ "Self-owned? #{shutdown_mutex.owned?}"
81
+ shutdown_mutex.synchronize {
82
+ Rails.logger.debug "AKITA: Acquired shutdown mutex "\
83
+ "#{shutdown_mutex} for file #{out_file_name} "\
84
+ "while shutting down in #{Thread.current}."
85
+ Rails.logger.debug "AKITA: About to release shutdown mutex "\
86
+ "#{shutdown_mutex} for file #{out_file_name} "\
87
+ "while shutting down in #{Thread.current}."
88
+ }
63
89
  end
64
90
  end
65
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akita-har_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jed Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec