testa_logger 0.1.14 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/Gemfile.lock +1 -1
- data/lib/testa_logger/logger/dispatcher.rb +13 -3
- data/lib/testa_logger/logger/options.rb +4 -1
- data/lib/testa_logger/logger/persistence.rb +2 -1
- data/lib/testa_logger/logger.rb +22 -30
- data/lib/testa_logger/version.rb +1 -1
- 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: dfd803d381aec073541589279ce2694765b9b3f523d945b73dfa208bc6a57f1d
|
4
|
+
data.tar.gz: 43e6b677000f40c5bb1dd26a0d759ff73e5e7d2e1190c9488ed022168e05b830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77e2682e1e0fc974381a3902c913f1d2c026131ebf8cf8dcccbb2bcb6d5579cda3baa5eb39314fa227270e2c700529dfcc0b011cff5fbf1e2a4e989fff3f2c0d
|
7
|
+
data.tar.gz: 144a1e7fdf367b688aa387707841467de75f7ee71850bf96f0167219e61b3727c693581689c10421fc58ae0dfc5044454d23c6bb71435752a23bb30c146da1fc
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,6 +9,9 @@ module TestaLogger
|
|
9
9
|
def initialize(logger, faye_url, faye_token)
|
10
10
|
@logger = logger
|
11
11
|
@uri = URI.parse(faye_url)
|
12
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
13
|
+
@http.read_timeout = 2
|
14
|
+
@http.open_timeout = 2
|
12
15
|
@faye_token = faye_token
|
13
16
|
@channel = "/logs/live/#{logger.app}/#{logger.group}"
|
14
17
|
@channel += "/#{logger.subgroup}" unless logger.subgroup.nil?
|
@@ -17,15 +20,19 @@ module TestaLogger
|
|
17
20
|
at_exit { dispatch }
|
18
21
|
end
|
19
22
|
|
20
|
-
def push(level, time, tag,
|
23
|
+
def push(level, time, tag, message, log)
|
21
24
|
# after forking process, dispatch thread will stop working in the forked process
|
22
25
|
run_dispatch_thread if @dispatch_thread.nil? || @dispatch_thread.status == false
|
23
26
|
|
24
27
|
data = {
|
28
|
+
app: logger.app,
|
29
|
+
group: logger.group,
|
30
|
+
subgroup: logger.subgroup,
|
25
31
|
level: level,
|
26
32
|
time: time,
|
27
33
|
tag: tag,
|
28
|
-
|
34
|
+
message: message,
|
35
|
+
log: log,
|
29
36
|
}
|
30
37
|
@outbox << data
|
31
38
|
end
|
@@ -57,7 +64,10 @@ module TestaLogger
|
|
57
64
|
data: { logs: @outbox },
|
58
65
|
ext: { auth_token: @faye_token },
|
59
66
|
}
|
60
|
-
|
67
|
+
|
68
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
69
|
+
request.form_data = { message: message.to_json }
|
70
|
+
@http.request(request)
|
61
71
|
@outbox.clear
|
62
72
|
end
|
63
73
|
end
|
@@ -12,7 +12,7 @@ module TestaLogger
|
|
12
12
|
attr_accessor :formatter
|
13
13
|
|
14
14
|
# @return [TrueClass, FalseClass]
|
15
|
-
attr_accessor :live, :persist
|
15
|
+
attr_accessor :live, :persist, :stdout
|
16
16
|
|
17
17
|
# @return [String, nil]
|
18
18
|
attr_accessor :filepath
|
@@ -31,6 +31,7 @@ module TestaLogger
|
|
31
31
|
"#{app_and_groups}[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{format('%-5.5s', severity)} -- : #{msg}\n"
|
32
32
|
end
|
33
33
|
@live = false
|
34
|
+
@stdout = false
|
34
35
|
@filepath = nil
|
35
36
|
@tag_length = 13
|
36
37
|
@persist = true # requires aws credentials set in env variables
|
@@ -44,6 +45,7 @@ module TestaLogger
|
|
44
45
|
}
|
45
46
|
|
46
47
|
handle_user_options(options)
|
48
|
+
@live = false if app == "ws" # will cause endless loop otherwise
|
47
49
|
end
|
48
50
|
|
49
51
|
def format_app_and_groups(app, group, subgroup)
|
@@ -65,6 +67,7 @@ module TestaLogger
|
|
65
67
|
end
|
66
68
|
@formatter = options[:formatter] unless options[:formatter].nil?
|
67
69
|
@live = options[:live] unless options[:live].nil?
|
70
|
+
@stdout = options[:stdout] unless options[:stdout].nil?
|
68
71
|
@filepath = File.expand_path(options[:filepath]) unless options[:filepath].nil?
|
69
72
|
@tag_length = options[:tag_length] unless options[:tag_length].nil?
|
70
73
|
@persist = options[:persist] unless options[:persist].nil?
|
@@ -37,10 +37,11 @@ module TestaLogger
|
|
37
37
|
|
38
38
|
key = "logs/#{app}/#{group}"
|
39
39
|
key += "/#{subgroup}" unless subgroup.nil?
|
40
|
+
key += "/#{Time.now.strftime('%d.%m.%Y')}"
|
40
41
|
|
41
42
|
extension = File.extname(options.filepath)
|
42
43
|
filename = File.basename(options.filepath, extension)
|
43
|
-
time_string = Time.now.strftime("%H_%M_%
|
44
|
+
time_string = Time.now.strftime("%H_%M_%S")
|
44
45
|
key += "/#{filename}_#{time_string}#{extension}"
|
45
46
|
|
46
47
|
# stop writing into log file with it is being attached, otherwise checksum integrity will fail.
|
data/lib/testa_logger/logger.rb
CHANGED
@@ -179,28 +179,6 @@ module TestaLogger
|
|
179
179
|
result
|
180
180
|
end
|
181
181
|
|
182
|
-
class << self
|
183
|
-
def default_options
|
184
|
-
OpenStruct.new(
|
185
|
-
shift_age: "daily",
|
186
|
-
level: DEBUG,
|
187
|
-
formatter: default_formatter,
|
188
|
-
live: false,
|
189
|
-
filepath: nil,
|
190
|
-
tag_length: 13,
|
191
|
-
persist: true, # requires aws credentials set in env variables
|
192
|
-
faye_url: ENV["WEB_SOCKET_URL"],
|
193
|
-
faye_token: ENV["FAYE_TOKEN"],
|
194
|
-
s3_creds: {
|
195
|
-
region: ENV["AWS_REGION"],
|
196
|
-
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
197
|
-
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
|
198
|
-
bucket_name: ENV["S3_BUCKET_NAME"],
|
199
|
-
}
|
200
|
-
)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
182
|
private
|
205
183
|
|
206
184
|
def add_log_to_queue(level, tag, args, &block)
|
@@ -208,12 +186,22 @@ module TestaLogger
|
|
208
186
|
|
209
187
|
time = Time.now
|
210
188
|
tag = extract_tag(tag, args)
|
211
|
-
|
189
|
+
message = merge_message_args(args, &block)
|
190
|
+
tag_and_message = merge_tag_and_message(tag, args, &block)
|
212
191
|
formatted_severity = format_severity(level)
|
213
|
-
|
192
|
+
log = format_message(formatted_severity, time, "", tag_and_message)
|
193
|
+
|
194
|
+
# after forking process, write thread will stop working in the forked process
|
195
|
+
start_write_thread if @write_thread.nil? || @write_thread.status == false
|
196
|
+
@queue << log
|
197
|
+
@dispatcher.push(level, time, tag, message, log) if options.live
|
198
|
+
return unless options.stdout
|
214
199
|
|
215
|
-
|
216
|
-
|
200
|
+
if level >= ERROR
|
201
|
+
warn log
|
202
|
+
else
|
203
|
+
puts log
|
204
|
+
end
|
217
205
|
end
|
218
206
|
|
219
207
|
# rails and other applications do not use tags,
|
@@ -228,9 +216,13 @@ module TestaLogger
|
|
228
216
|
tag
|
229
217
|
end
|
230
218
|
|
231
|
-
def
|
219
|
+
def merge_message_args(args, &block)
|
232
220
|
args.push(block.call) if block
|
233
|
-
|
221
|
+
args_to_string(args.compact).to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
def merge_tag_and_message(tag, message)
|
225
|
+
"[#{padded_tag(tag)}]: #{message}"
|
234
226
|
end
|
235
227
|
|
236
228
|
def padded_tag(tag)
|
@@ -255,8 +247,8 @@ module TestaLogger
|
|
255
247
|
SEV_LABEL[severity] || "UNKNOWN"
|
256
248
|
end
|
257
249
|
|
258
|
-
def format_message(severity, datetime, progname,
|
259
|
-
options.formatter.call(severity, datetime, progname,
|
250
|
+
def format_message(severity, datetime, progname, tag_and_message)
|
251
|
+
options.formatter.call(severity, datetime, progname, tag_and_message)
|
260
252
|
end
|
261
253
|
end
|
262
254
|
end
|
data/lib/testa_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testa_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- karlo.razumovic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|