testa_logger 0.1.11 → 0.1.14

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: 9abd8b05802cd093378bdd4e006bb8a9483f38039f4deea5d3724d59ad3934f3
4
- data.tar.gz: 59eb5fbf5b3c2cae7af56fdc757e73836309d70342e0f76dc3bd1478efa828e3
3
+ metadata.gz: 1a925b10a67aa850c7b52f01d423b3c4f227ddd638f0c0180735752639a60649
4
+ data.tar.gz: 27924bc4702af164ab79646219d2f2545137789eddcd5bb66abb6a3104457f50
5
5
  SHA512:
6
- metadata.gz: 32b30e0f1d8be82ced9a9d0e850fc1b54bae7cf19efc8c47d3d930ba899cec59ae8b14ea454f46f15f5a3a6f4c1c4dd9552ee98eb627356836c1904d54647536
7
- data.tar.gz: b1eb6bca379197c63b1e6360dd9a3ffd29f3381e88b2f9883fc74bba4985ca144332223c74aae47d6955069b854c287824583ae6c9e3876e61f563a78bf33811
6
+ metadata.gz: 60452c35d41dc37ef106d5dc89d8926882877b94c3a5cc2f3b49656772476aae07417ebb39c67e6baa81c2bd82a21f95725eac2544721601c9273965d975a629
7
+ data.tar.gz: 813a62359cee488550bbc4e042a93cc6c1a34c1b8b19b50ce76ce91c8d486d537b9aca841c7229e3dc5e5335f986eb9a58938530c430b12c0cac6e4527d3d1a0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testa_logger (0.1.11)
4
+ testa_logger (0.1.14)
5
5
  activesupport
6
6
  awesome_print
7
7
  aws-sdk-s3
@@ -1,17 +1,26 @@
1
1
  module TestaLogger
2
2
  class Logger
3
3
  class Dispatcher
4
- def initialize(faye_url, faye_token, app, group, subgroup = nil)
4
+ TAG = "Logger::Dispatcher"
5
+
6
+ # @return [Logger]
7
+ attr_accessor :logger
8
+
9
+ def initialize(logger, faye_url, faye_token)
10
+ @logger = logger
5
11
  @uri = URI.parse(faye_url)
6
12
  @faye_token = faye_token
7
- @channel = "/logs/live/#{app}/#{group}"
8
- @channel += "/#{subgroup}" unless subgroup.nil?
13
+ @channel = "/logs/live/#{logger.app}/#{logger.group}"
14
+ @channel += "/#{logger.subgroup}" unless logger.subgroup.nil?
9
15
  @outbox = Concurrent::Array.new
10
16
  run_dispatch_thread
11
17
  at_exit { dispatch }
12
18
  end
13
19
 
14
20
  def push(level, time, tag, formatted_text)
21
+ # after forking process, dispatch thread will stop working in the forked process
22
+ run_dispatch_thread if @dispatch_thread.nil? || @dispatch_thread.status == false
23
+
15
24
  data = {
16
25
  level: level,
17
26
  time: time,
@@ -22,18 +31,22 @@ module TestaLogger
22
31
  end
23
32
 
24
33
  def run_dispatch_thread
25
- Thread.new do
34
+ @dispatch_thread = Thread.new do
26
35
  max_delay = 0.5
27
36
  max_buffer = 20
28
37
  last_sent = Time.now.to_f
29
38
  loop do
30
- sleep 0.1
31
- next unless (last_sent + max_delay < Time.now.to_f) || @outbox.count > max_buffer
39
+ begin # rubocop:disable Style/RedundantBegin
40
+ sleep 0.1
41
+ next unless (last_sent + max_delay < Time.now.to_f) || @outbox.count > max_buffer
32
42
 
33
- last_sent = Time.now.to_f
34
- next if @outbox.count.zero?
43
+ last_sent = Time.now.to_f
44
+ next if @outbox.count.zero?
35
45
 
36
- dispatch
46
+ dispatch
47
+ rescue StandardError => e
48
+ logger.error(TAG, e)
49
+ end
37
50
  end
38
51
  end
39
52
  end
@@ -58,11 +58,9 @@ module TestaLogger
58
58
 
59
59
  def setup_dispatcher
60
60
  @dispatcher = Dispatcher.new(
61
+ self,
61
62
  options.faye_url,
62
- options.faye_token,
63
- app,
64
- group,
65
- subgroup
63
+ options.faye_token
66
64
  )
67
65
  end
68
66
 
@@ -82,27 +80,27 @@ module TestaLogger
82
80
  options.formatter
83
81
  end
84
82
 
85
- def debug(tag = NO_TAG, *args, &block)
83
+ def debug(tag = "", *args, &block)
86
84
  add_log_to_queue(DEBUG, tag, args, &block)
87
85
  end
88
86
 
89
- def info(tag = NO_TAG, *args, &block)
87
+ def info(tag = "", *args, &block)
90
88
  add_log_to_queue(INFO, tag, args, &block)
91
89
  end
92
90
 
93
- def warn(tag = NO_TAG, *args, &block)
91
+ def warn(tag = "", *args, &block)
94
92
  add_log_to_queue(WARN, tag, args, &block)
95
93
  end
96
94
 
97
- def error(tag = NO_TAG, *args, &block)
95
+ def error(tag = "", *args, &block)
98
96
  add_log_to_queue(ERROR, tag, args, &block)
99
97
  end
100
98
 
101
- def fatal(tag = NO_TAG, *args, &block)
99
+ def fatal(tag = "", *args, &block)
102
100
  add_log_to_queue(FATAL, tag, args, &block)
103
101
  end
104
102
 
105
- def unknown(tag = NO_TAG, *args, &block)
103
+ def unknown(tag = "", *args, &block)
106
104
  add_log_to_queue(UNKNOWN, tag, args, &block)
107
105
  end
108
106
 
@@ -1,3 +1,3 @@
1
1
  module TestaLogger
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.14"
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.11
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic