testa_logger 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/Gemfile.lock +1 -1
- data/lib/testa_logger/logger/dispatcher.rb +6 -2
- data/lib/testa_logger/logger/options.rb +3 -1
- data/lib/testa_logger/logger/persistence.rb +2 -1
- data/lib/testa_logger/logger.rb +20 -30
- data/lib/testa_logger/version.rb +1 -1
- metadata +1 -1
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
@@ -20,15 +20,19 @@ module TestaLogger
|
|
20
20
|
at_exit { dispatch }
|
21
21
|
end
|
22
22
|
|
23
|
-
def push(level, time, tag,
|
23
|
+
def push(level, time, tag, message, log)
|
24
24
|
# after forking process, dispatch thread will stop working in the forked process
|
25
25
|
run_dispatch_thread if @dispatch_thread.nil? || @dispatch_thread.status == false
|
26
26
|
|
27
27
|
data = {
|
28
|
+
app: logger.app,
|
29
|
+
group: logger.group,
|
30
|
+
subgroup: logger.subgroup,
|
28
31
|
level: level,
|
29
32
|
time: time,
|
30
33
|
tag: tag,
|
31
|
-
|
34
|
+
message: message,
|
35
|
+
log: log,
|
32
36
|
}
|
33
37
|
@outbox << data
|
34
38
|
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
|
@@ -66,6 +67,7 @@ module TestaLogger
|
|
66
67
|
end
|
67
68
|
@formatter = options[:formatter] unless options[:formatter].nil?
|
68
69
|
@live = options[:live] unless options[:live].nil?
|
70
|
+
@stdout = options[:stdout] unless options[:stdout].nil?
|
69
71
|
@filepath = File.expand_path(options[:filepath]) unless options[:filepath].nil?
|
70
72
|
@tag_length = options[:tag_length] unless options[:tag_length].nil?
|
71
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,14 +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)
|
214
193
|
|
215
194
|
# after forking process, write thread will stop working in the forked process
|
216
195
|
start_write_thread if @write_thread.nil? || @write_thread.status == false
|
217
|
-
@queue <<
|
218
|
-
@dispatcher.push(level, time, tag,
|
196
|
+
@queue << log
|
197
|
+
@dispatcher.push(level, time, tag, message, log) if options.live
|
198
|
+
return unless options.stdout
|
199
|
+
|
200
|
+
if level >= ERROR
|
201
|
+
warn log
|
202
|
+
else
|
203
|
+
puts log
|
204
|
+
end
|
219
205
|
end
|
220
206
|
|
221
207
|
# rails and other applications do not use tags,
|
@@ -230,9 +216,13 @@ module TestaLogger
|
|
230
216
|
tag
|
231
217
|
end
|
232
218
|
|
233
|
-
def
|
219
|
+
def merge_message_args(args, &block)
|
234
220
|
args.push(block.call) if block
|
235
|
-
|
221
|
+
args_to_string(args.compact).to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
def merge_tag_and_message(tag, message)
|
225
|
+
"[#{padded_tag(tag)}]: #{message}"
|
236
226
|
end
|
237
227
|
|
238
228
|
def padded_tag(tag)
|
@@ -257,8 +247,8 @@ module TestaLogger
|
|
257
247
|
SEV_LABEL[severity] || "UNKNOWN"
|
258
248
|
end
|
259
249
|
|
260
|
-
def format_message(severity, datetime, progname,
|
261
|
-
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)
|
262
252
|
end
|
263
253
|
end
|
264
254
|
end
|
data/lib/testa_logger/version.rb
CHANGED