testa_logger 0.1.25 → 0.1.27

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: bc6c84783d220d2af496913f858931653022b56d7a38044784c123c63e7bb28c
4
- data.tar.gz: d4996b162dc10543d5a31de795a87ed63751455496e8bb82cb2805bacac8d227
3
+ metadata.gz: 6ea01fffdf48772f4fa366f3e4730c53aa7dd1d366fd3b16e839acfde756e876
4
+ data.tar.gz: 3fd7fe0c69af421586140b6be1d2d811312a7e338059331938c751a7d1ef2f62
5
5
  SHA512:
6
- metadata.gz: 1db32672398e7ef8b986ebd0d635b3af8519c16eb0a40117d85f1c3c84d8fb82819ea8243a7f5b1fe3bc390c81ae2b5976d57d89c61e1821d4516850cb8874b6
7
- data.tar.gz: '025723923e35af867e146992ec4f6675092e9898fd97b56867ee37752b552bfcc2f31e2276e94b399c307db1da06994a392fda8fb293e4a14a93274563c6e584'
6
+ metadata.gz: 4d9121752a32f087931db122c6268f2d1a98470a19a440b2315d34c776e5200c61269e8825508a145181b4fb291c007c5df6231d2289f346ba15e04f29a7df08
7
+ data.tar.gz: c7cd4e516d98b52959b8db64b3168af65ebe1f938bac24d9194557311d3f0f8de9a028cb8733b8e369587ba25314b7b6905d2154f4337f2516cd271fa7e0c53b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testa_logger (0.1.24)
4
+ testa_logger (0.1.27)
5
5
  activesupport
6
6
  awesome_print
7
7
  aws-sdk-s3
@@ -20,8 +20,8 @@ GEM
20
20
  ast (2.4.2)
21
21
  awesome_print (1.9.2)
22
22
  aws-eventstream (1.2.0)
23
- aws-partitions (1.621.0)
24
- aws-sdk-core (3.133.0)
23
+ aws-partitions (1.620.0)
24
+ aws-sdk-core (3.132.0)
25
25
  aws-eventstream (~> 1, >= 1.0.2)
26
26
  aws-partitions (~> 1, >= 1.525.0)
27
27
  aws-sigv4 (~> 1.1)
@@ -41,13 +41,13 @@ module TestaLogger
41
41
  begin
42
42
  @dev.write(message)
43
43
  rescue StandardError => e
44
- warn("log writing failed. #{e}")
44
+ warn("log writing failed 1. #{e}")
45
45
  end
46
46
  end
47
47
  rescue SystemExit
48
48
  exit 1
49
49
  rescue Exception => e
50
- warn("log writing failed. #{e}")
50
+ warn("log writing failed 2. #{e}")
51
51
  end
52
52
 
53
53
  def close
@@ -17,15 +17,13 @@ module TestaLogger
17
17
  raise IoPersistenceError if @log_device.is_a?(IO)
18
18
 
19
19
  begin
20
- # stop writing into log file with it is being attached, otherwise checksum integrity will fail.
21
- write_thread["stop"] = true
20
+ @pause = true
22
21
  record.send(attachment_name).attach(io: File.open(options.filepath), filename: "#{attachment_name}.log")
23
22
  rescue StandardError => e
24
23
  error(TAG, e)
25
24
  raise
26
25
  ensure
27
- write_thread["stop"] = false
28
- write_thread.run
26
+ @pause = false
29
27
  end
30
28
  end
31
29
 
@@ -33,7 +31,7 @@ module TestaLogger
33
31
  return if @s3.nil?
34
32
 
35
33
  begin
36
- write_thread["stop"] = true
34
+ @pause = true
37
35
 
38
36
  key = "logs/#{app}/#{group}"
39
37
  key += "/#{subgroup}" unless subgroup.nil?
@@ -44,7 +42,6 @@ module TestaLogger
44
42
  time_string = Time.now.strftime("%H_%M_%S")
45
43
  key += "/#{filename}_#{time_string}#{extension}"
46
44
 
47
- # stop writing into log file with it is being attached, otherwise checksum integrity will fail.
48
45
  response = @s3.put_object(
49
46
  bucket: options.s3_credentials[:bucket_name],
50
47
  key: key,
@@ -55,8 +52,7 @@ module TestaLogger
55
52
  error(TAG, e)
56
53
  raise
57
54
  ensure
58
- write_thread["stop"] = false
59
- write_thread.run
55
+ @pause = false
60
56
  end
61
57
  end
62
58
  end
@@ -34,15 +34,16 @@ module TestaLogger
34
34
  NO_TAG = "NO-TAG"
35
35
 
36
36
  def initialize(app, group, subgroup = nil, options = {})
37
+ @pause = false
38
+ @pending_logs = []
39
+
37
40
  @app = app
38
41
  @group = group
39
42
  @subgroup = subgroup
40
43
  @options = Options.new(app, group, subgroup, options)
41
44
  create_log_file
42
45
  setup_dispatcher
43
- # start_write_thread
44
46
  init_s3_client if @options.persist
45
- # at_exit { flush_queue }
46
47
  end
47
48
 
48
49
  def create_log_file
@@ -65,51 +66,32 @@ module TestaLogger
65
66
  )
66
67
  end
67
68
 
68
- def start_write_thread
69
- @pid = Process.pid
70
- # we must use this queue in order to be able to collect logs in trap context
71
- @queue = Queue.new
72
- @write_thread = Thread.new do
73
- loop { queue_pop }
74
- end
75
- end
76
-
77
- def flush_queue
78
- queue_pop while @queue.size.positive?
79
- end
80
-
81
- def queue_pop
82
- text = @queue.pop
83
- Thread.stop if Thread.current["stop"]
84
- @log_device.write(text)
85
- end
86
-
87
69
  def formatter
88
70
  options.formatter
89
71
  end
90
72
 
91
73
  def debug(tag = nil, *args, &block)
92
- add_log_to_queue(DEBUG, tag, args, &block)
74
+ add(DEBUG, tag, args, &block)
93
75
  end
94
76
 
95
77
  def info(tag = nil, *args, &block)
96
- add_log_to_queue(INFO, tag, args, &block)
78
+ add(INFO, tag, args, &block)
97
79
  end
98
80
 
99
81
  def warn(tag = nil, *args, &block)
100
- add_log_to_queue(WARN, tag, args, &block)
82
+ add(WARN, tag, args, &block)
101
83
  end
102
84
 
103
85
  def error(tag = nil, *args, &block)
104
- add_log_to_queue(ERROR, tag, args, &block)
86
+ add(ERROR, tag, args, &block)
105
87
  end
106
88
 
107
89
  def fatal(tag = nil, *args, &block)
108
- add_log_to_queue(FATAL, tag, args, &block)
90
+ add(FATAL, tag, args, &block)
109
91
  end
110
92
 
111
93
  def unknown(tag = nil, *args, &block)
112
- add_log_to_queue(UNKNOWN, tag, args, &block)
94
+ add(UNKNOWN, tag, args, &block)
113
95
  end
114
96
 
115
97
  def level=(severity)
@@ -189,7 +171,7 @@ module TestaLogger
189
171
 
190
172
  private
191
173
 
192
- def add_log_to_queue(level, tag, args, &block)
174
+ def add(level, tag, args, &block)
193
175
  return if level < options.level
194
176
 
195
177
  time = Time.now
@@ -199,10 +181,18 @@ module TestaLogger
199
181
  formatted_severity = format_severity(level)
200
182
  log = format_message(formatted_severity, time, "", tag_and_message)
201
183
 
202
- # after forking process, write thread will stop working in the forked process
203
- # start_write_thread if @pid.nil? || @pid != Process.pid
204
- # @queue << log
205
- @log_device.write(log)
184
+ if @pause
185
+ @pending_logs << log
186
+ else
187
+ if @pending_logs.count.positive?
188
+ @pending_logs.each do |pending_log|
189
+ @log_device.write(pending_log)
190
+ end
191
+ @pending_logs.clear
192
+ end
193
+ @log_device.write(log)
194
+ end
195
+
206
196
  @dispatcher.push(level, time, tag, message, log) if options.live
207
197
  return unless options.stdout
208
198
 
@@ -1,3 +1,3 @@
1
1
  module TestaLogger
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.27"
3
3
  end
data/logger.iml CHANGED
@@ -11,6 +11,8 @@
11
11
  <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.6) [gem]" level="application" />
12
12
  <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.9.2, RVM: ruby-2.7.6) [gem]" level="application" />
13
13
  <orderEntry type="library" scope="PROVIDED" name="aws-eventstream (v1.2.0, RVM: ruby-2.7.6) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="aws-partitions (v1.620.0, RVM: ruby-2.7.6) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="aws-sdk-core (v3.132.0, RVM: ruby-2.7.6) [gem]" level="application" />
14
16
  <orderEntry type="library" scope="PROVIDED" name="aws-sdk-kms (v1.58.0, RVM: ruby-2.7.6) [gem]" level="application" />
15
17
  <orderEntry type="library" scope="PROVIDED" name="aws-sdk-s3 (v1.114.0, RVM: ruby-2.7.6) [gem]" level="application" />
16
18
  <orderEntry type="library" scope="PROVIDED" name="aws-sigv4 (v1.5.1, RVM: ruby-2.7.6) [gem]" level="application" />
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.25
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic