testa_logger 0.1.14 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a925b10a67aa850c7b52f01d423b3c4f227ddd638f0c0180735752639a60649
4
- data.tar.gz: 27924bc4702af164ab79646219d2f2545137789eddcd5bb66abb6a3104457f50
3
+ metadata.gz: dfd803d381aec073541589279ce2694765b9b3f523d945b73dfa208bc6a57f1d
4
+ data.tar.gz: 43e6b677000f40c5bb1dd26a0d759ff73e5e7d2e1190c9488ed022168e05b830
5
5
  SHA512:
6
- metadata.gz: 60452c35d41dc37ef106d5dc89d8926882877b94c3a5cc2f3b49656772476aae07417ebb39c67e6baa81c2bd82a21f95725eac2544721601c9273965d975a629
7
- data.tar.gz: 813a62359cee488550bbc4e042a93cc6c1a34c1b8b19b50ce76ce91c8d486d537b9aca841c7229e3dc5e5335f986eb9a58938530c430b12c0cac6e4527d3d1a0
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.14)
4
+ testa_logger (0.1.17)
5
5
  activesupport
6
6
  awesome_print
7
7
  aws-sdk-s3
@@ -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, formatted_text)
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
- formatted_text: formatted_text,
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
- Net::HTTP.post_form(@uri, message: message.to_json)
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_%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,12 +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)
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
- @queue << formatted_text
216
- @dispatcher.push(level, time, tag, formatted_text) if options.live
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 create_log_string(tag, args, &block)
219
+ def merge_message_args(args, &block)
232
220
  args.push(block.call) if block
233
- "[#{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}"
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, msg)
259
- 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)
260
252
  end
261
253
  end
262
254
  end
@@ -1,3 +1,3 @@
1
1
  module TestaLogger
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.17"
3
3
  end
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.14
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-17 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport