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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/akita/har_logger.rb +36 -5
- data/lib/akita/har_logger/http_response.rb +3 -1
- data/lib/akita/har_logger/version.rb +1 -1
- data/lib/akita/har_logger/writer_thread.rb +55 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eed2465cdafed5eb9d0af31022054193efdcd6ba8b2866a466c51554e24ab43
|
4
|
+
data.tar.gz: 4553cd54a99c9d1a2958657e90b31deeb40e237d508bbd1b80c9cbc59064ef64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04ff7a6f33614994d7bc82d4fb52b5b3957be1f405df36316330dd811d7949968325eaf997276d775e85f1df17461c4733cebdae9eeef6fb0bd4be53f309cdb0
|
7
|
+
data.tar.gz: f0325184bc764d7eba84573d164bed1c676300cfac8f27b63dafea6f0ebafe80dd58cacc965c694830355c603a7a23b6c2435b3a1b92c22be89093c06869cc0e
|
data/Gemfile.lock
CHANGED
data/lib/akita/har_logger.rb
CHANGED
@@ -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
|
-
|
133
|
-
|
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
|
-
|
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
|
@@ -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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
41
|
+
first_entry = true
|
33
42
|
|
34
|
-
|
35
|
-
|
36
|
-
|
43
|
+
loop do
|
44
|
+
entry = entry_queue.pop
|
45
|
+
if entry == nil then break end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
47
|
+
# Emit comma separator if needed.
|
48
|
+
f.puts (first_entry ? '' : ',')
|
49
|
+
first_entry = false
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
# Emit the dequeued entry.
|
52
|
+
f.write JSON.generate(entry)
|
53
|
+
end
|
45
54
|
|
46
|
-
|
47
|
-
|
55
|
+
# Produce the epilogue.
|
56
|
+
f.write <<~EOF
|
48
57
|
|
49
|
-
|
58
|
+
]
|
59
|
+
}
|
50
60
|
}
|
51
|
-
|
52
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2021-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|