testa_logger 0.1.16 → 0.1.17

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: 6bccba94675dff6f881b604cec301bcea54e1a99b653db95c7ce156ddf8104de
4
- data.tar.gz: '05984a867c873368a4da65b0539a7e981cc0119e5076d142408e725066121cc4'
3
+ metadata.gz: dfd803d381aec073541589279ce2694765b9b3f523d945b73dfa208bc6a57f1d
4
+ data.tar.gz: 43e6b677000f40c5bb1dd26a0d759ff73e5e7d2e1190c9488ed022168e05b830
5
5
  SHA512:
6
- metadata.gz: 9995ca14b6c4b97370c2600ee5c401f6e8b54447f402d776e3e7f2882ef91d7cb724a0ecea3d418125991b11531ca0f5a2fcc7a7aba611c15b4e60f482a08022
7
- data.tar.gz: 15f463df8811cb1d16a72dfbb8b57f440fd73d55eb3ed8566ccc729b47b76831c3889679bf76c6749f406d6eeb66827be94a78275175c9c180dfeda6ece5bbe2
6
+ metadata.gz: 77e2682e1e0fc974381a3902c913f1d2c026131ebf8cf8dcccbb2bcb6d5579cda3baa5eb39314fa227270e2c700529dfcc0b011cff5fbf1e2a4e989fff3f2c0d
7
+ data.tar.gz: 144a1e7fdf367b688aa387707841467de75f7ee71850bf96f0167219e61b3727c693581689c10421fc58ae0dfc5044454d23c6bb71435752a23bb30c146da1fc
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  # we have to have per project rubcop files (IDE limitation),
2
2
  # but we want only one config across all projects
3
3
  # you can override any global cops here, in this file
4
- inherit_from: ../.rubocop.yml
4
+ inherit_from:
5
+ - ../.rubocop.yml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testa_logger (0.1.16)
4
+ testa_logger (0.1.17)
5
5
  activesupport
6
6
  awesome_print
7
7
  aws-sdk-s3
@@ -20,15 +20,19 @@ module TestaLogger
20
20
  at_exit { dispatch }
21
21
  end
22
22
 
23
- def push(level, time, tag, formatted_text)
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
- formatted_text: formatted_text,
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_%S__%d_%m_%Y")
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.
@@ -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
- text = create_log_string(tag, args, &block)
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
- formatted_text = format_message(formatted_severity, time, "", text)
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 << formatted_text
218
- @dispatcher.push(level, time, tag, formatted_text) if options.live
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 create_log_string(tag, args, &block)
219
+ def merge_message_args(args, &block)
234
220
  args.push(block.call) if block
235
- "[#{padded_tag(tag)}]: #{args_to_string(args.compact)}"
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, msg)
261
- options.formatter.call(severity, datetime, progname, msg)
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
@@ -1,3 +1,3 @@
1
1
  module TestaLogger
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testa_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic