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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/testa_logger/logger/dispatcher.rb +22 -9
- data/lib/testa_logger/logger.rb +8 -10
- 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: 1a925b10a67aa850c7b52f01d423b3c4f227ddd638f0c0180735752639a60649
|
4
|
+
data.tar.gz: 27924bc4702af164ab79646219d2f2545137789eddcd5bb66abb6a3104457f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60452c35d41dc37ef106d5dc89d8926882877b94c3a5cc2f3b49656772476aae07417ebb39c67e6baa81c2bd82a21f95725eac2544721601c9273965d975a629
|
7
|
+
data.tar.gz: 813a62359cee488550bbc4e042a93cc6c1a34c1b8b19b50ce76ce91c8d486d537b9aca841c7229e3dc5e5335f986eb9a58938530c430b12c0cac6e4527d3d1a0
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
module TestaLogger
|
2
2
|
class Logger
|
3
3
|
class Dispatcher
|
4
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
43
|
+
last_sent = Time.now.to_f
|
44
|
+
next if @outbox.count.zero?
|
35
45
|
|
36
|
-
|
46
|
+
dispatch
|
47
|
+
rescue StandardError => e
|
48
|
+
logger.error(TAG, e)
|
49
|
+
end
|
37
50
|
end
|
38
51
|
end
|
39
52
|
end
|
data/lib/testa_logger/logger.rb
CHANGED
@@ -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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
103
|
+
def unknown(tag = "", *args, &block)
|
106
104
|
add_log_to_queue(UNKNOWN, tag, args, &block)
|
107
105
|
end
|
108
106
|
|
data/lib/testa_logger/version.rb
CHANGED