act-fluent-logger-rails 0.5.0 → 0.6.0

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
  SHA1:
3
- metadata.gz: 125a872f83e8ef5c46ca1ca293b1365fcb3aed52
4
- data.tar.gz: bea7ea99906b406bfda4945cd0683c0e69c61638
3
+ metadata.gz: 7d902898eefca5581ae67b14013df2f2e9e9c261
4
+ data.tar.gz: 4971a8ca703b77495e12422db08dd136799827df
5
5
  SHA512:
6
- metadata.gz: d2d70096552e8e57783d48c0c055b9528648196aa8ae3863d54aae716c6976b2ab758a2058247df4ed58e3f23d7a6f71e251484cd85c6c0d0fede2694609089c
7
- data.tar.gz: 7f6b11895029ade7a9e2a80d5d4934a252f3f915f27878e22a705307c9d11daaba9790b07fc2619c55eb09af2b0ff8a598aa3695bb5e33c5a487ed4c1ac70a2c
6
+ metadata.gz: 2546af248a240f448f9357cb636190f2e160665a9ce8a02e74141ca491f8945138fbbaa735bb6ff24db74127bb6c47b077954820c8d99eaa6ffe4ed7d55d9434
7
+ data.tar.gz: 22d449f71d50989a3ee924b2f6b48c0f475b0adcdb39f7f1a009570b49e7031b3d01d16aab484533b33f6ec0979ea6401e631ff75b63d45ea756c146d4331820
@@ -1,10 +1,14 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
4
+ - gem install bundler -v '< 2'
2
5
  rvm:
3
6
  - 2.1.10
4
7
  - 2.2.10
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
8
+ - 2.3.8
9
+ - 2.4.5
10
+ - 2.5.3
11
+ - 2.6.1
8
12
  gemfile:
9
13
  - gemfiles/rails_4.0.gemfile
10
14
  - gemfiles/rails_4.1.gemfile
@@ -12,6 +16,7 @@ gemfile:
12
16
  - gemfiles/rails_5.0.gemfile
13
17
  - gemfiles/rails_5.1.gemfile
14
18
  - gemfiles/rails_5.2.gemfile
19
+ - gemfiles/rails_6.0.gemfile
15
20
  matrix:
16
21
  exclude:
17
22
  - rvm: 2.1.10
@@ -20,11 +25,23 @@ matrix:
20
25
  gemfile: gemfiles/rails_5.1.gemfile
21
26
  - rvm: 2.1.10
22
27
  gemfile: gemfiles/rails_5.2.gemfile
23
- - rvm: 2.4.4
28
+ - rvm: 2.1.10
29
+ gemfile: gemfiles/rails_6.0.gemfile
30
+ - rvm: 2.2.10
31
+ gemfile: gemfiles/rails_6.0.gemfile
32
+ - rvm: 2.3.8
33
+ gemfile: gemfiles/rails_6.0.gemfile
34
+ - rvm: 2.4.5
35
+ gemfile: gemfiles/rails_4.0.gemfile
36
+ - rvm: 2.4.5
37
+ gemfile: gemfiles/rails_4.1.gemfile
38
+ - rvm: 2.4.5
39
+ gemfile: gemfiles/rails_6.0.gemfile
40
+ - rvm: 2.5.3
24
41
  gemfile: gemfiles/rails_4.0.gemfile
25
- - rvm: 2.4.4
42
+ - rvm: 2.5.3
26
43
  gemfile: gemfiles/rails_4.1.gemfile
27
- - rvm: 2.5.1
44
+ - rvm: 2.6.1
28
45
  gemfile: gemfiles/rails_4.0.gemfile
29
- - rvm: 2.5.1
46
+ - rvm: 2.6.1
30
47
  gemfile: gemfiles/rails_4.1.gemfile
data/Appraisals CHANGED
@@ -27,3 +27,8 @@ appraise 'rails-5.2' do
27
27
  gem 'railties', '5.2.0'
28
28
  gem 'activesupport', '5.2.0'
29
29
  end
30
+
31
+ appraise 'rails-6.0' do
32
+ gem 'railties', '6.0.0.beta2'
33
+ gem 'activesupport', '6.0.0.beta2'
34
+ end
@@ -1,3 +1,8 @@
1
+ ## 0.6.0 / Nov 23 2019
2
+
3
+ * Rails 6
4
+ * Make Thread Safe
5
+
1
6
  ## 0.5.0 / April 29 2017
2
7
 
3
8
  * Rails 5.2
data/README.md CHANGED
@@ -4,7 +4,7 @@ Fluent logger.
4
4
 
5
5
  ## Supported versions
6
6
 
7
- * Rails 4 and 5
7
+ * Rails 4, 5, 6
8
8
 
9
9
  ## Installation
10
10
 
@@ -20,6 +20,6 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_development_dependency "rspec", '~> 3.5.0'
22
22
  gem.add_runtime_dependency "fluent-logger"
23
- gem.add_runtime_dependency "railties", ">= 4", "< 5.3"
24
- gem.add_runtime_dependency "activesupport", ">= 4", "< 5.3"
23
+ gem.add_runtime_dependency "railties", ">= 4", "< 6.1"
24
+ gem.add_runtime_dependency "activesupport", ">= 4", "< 6.1"
25
25
  end
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "railties", "6.0.0.beta3"
7
+ gem "activesupport", "6.0.0.beta3"
8
+
9
+ gemspec path: "../"
@@ -66,7 +66,8 @@ module ActFluentLoggerRails
66
66
  end
67
67
 
68
68
  def tagged(*tags)
69
- @tags = tags.flatten
69
+ @tags_thread_key ||= "fluentd_tagged_logging_tags:#{object_id}".freeze
70
+ Thread.current[@tags_thread_key] = tags.flatten
70
71
  yield self
71
72
  ensure
72
73
  flush
@@ -86,9 +87,7 @@ module ActFluentLoggerRails
86
87
  logger_opts = {host: host, port: port, nanosecond_precision: nanosecond_precision}
87
88
  @fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, logger_opts)
88
89
  @severity = 0
89
- @messages = []
90
90
  @log_tags = log_tags
91
- @map = {}
92
91
  after_initialize if respond_to? :after_initialize
93
92
  end
94
93
 
@@ -115,41 +114,55 @@ module ActFluentLoggerRails
115
114
  end
116
115
 
117
116
  if message.encoding == Encoding::UTF_8
118
- @messages << message
117
+ logger_messages << message
119
118
  else
120
- @messages << message.dup.force_encoding(Encoding::UTF_8)
119
+ logger_messages << message.dup.force_encoding(Encoding::UTF_8)
121
120
  end
122
121
 
123
122
  flush if @flush_immediately
124
123
  end
125
124
 
126
125
  def [](key)
127
- @map[key]
126
+ map[key]
128
127
  end
129
128
 
130
129
  def []=(key, value)
131
- @map[key] = value
130
+ map[key] = value
132
131
  end
133
132
 
134
133
  def flush
135
- return if @messages.empty?
134
+ return if logger_messages.empty?
136
135
  messages = if @messages_type == :string
137
- @messages.join("\n")
136
+ logger_messages.join("\n")
138
137
  else
139
- @messages
138
+ logger_messages
140
139
  end
141
- @map[:messages] = messages
142
- @map[@severity_key] = format_severity(@severity)
143
- if @tags
144
- @log_tags.keys.zip(@tags).each do |k, v|
145
- @map[k] = v
146
- end
147
- end
148
- @fluent_logger.post(@tag, @map)
140
+ map[:messages] = messages
141
+ map[@severity_key] = format_severity(@severity)
142
+ add_tags
143
+
144
+ @fluent_logger.post(@tag, map)
149
145
  @severity = 0
150
- @messages.clear
151
- @tags = nil
152
- @map.clear
146
+ logger_messages.clear
147
+ Thread.current[@tags_thread_key] = nil if @tags_thread_key
148
+ map.clear
149
+ end
150
+
151
+ def add_tags
152
+ return unless @tags_thread_key && Thread.current.key?(@tags_thread_key)
153
+ @log_tags.keys.zip(Thread.current[@tags_thread_key]).each do |k, v|
154
+ map[k] = v
155
+ end
156
+ end
157
+
158
+ def logger_messages
159
+ @messages_thread_key ||= "fluentd_logger_messages:#{object_id}".freeze
160
+ Thread.current[@messages_thread_key] ||= []
161
+ end
162
+
163
+ def map
164
+ @map_thread_key ||= "fluentd_logger_map:#{object_id}".freeze
165
+ Thread.current[@map_thread_key] ||= {}
153
166
  end
154
167
 
155
168
  def close
@@ -1,3 +1,3 @@
1
1
  module ActFluentLoggerRails
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -52,7 +52,6 @@ EOF
52
52
  }
53
53
 
54
54
  describe 'logging' do
55
-
56
55
  describe 'basic' do
57
56
  it 'info' do
58
57
  # see Rails::Rack::compute_tags
@@ -86,6 +85,39 @@ EOF
86
85
  end
87
86
  end
88
87
 
88
+ it 'is thread safe' do
89
+ threads = ['hello', 'world'].map do |tag_name|
90
+ Thread.new {
91
+ if tag_name == 'hello'
92
+ request = double('request', uuid: tag_name)
93
+ tags = log_tags.values.collect do |tag|
94
+ case tag
95
+ when Proc
96
+ tag.call(request)
97
+ when Symbol
98
+ request.send(tag)
99
+ else
100
+ tag
101
+ end
102
+ end
103
+ else
104
+ tags = []
105
+ end
106
+ logger.info(tag_name)
107
+ logger.tagged(tags) { sleep(1) if tag_name == 'hello'; logger.info(tag_name) }
108
+ }
109
+ end
110
+
111
+ while threads.any?(&:alive?)
112
+ sleep(0.1)
113
+ end
114
+ expect(@my_logger.log).to match_array([
115
+ ['foo', { messages: ['hello', 'hello'], severity: 'INFO', uuid: 'hello', foo: 'foo_value' } ],
116
+ ['foo', { messages: ['world', 'world'], severity: 'INFO', uuid: nil, foo: nil } ]
117
+ ])
118
+ end
119
+
120
+
89
121
  describe 'frozen ascii-8bit string' do
90
122
  before do
91
123
  logger.instance_variable_set(:@messages_type, :string)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act-fluent-logger-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAHARA Yoshinori
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2019-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: '4'
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
- version: '5.3'
50
+ version: '6.1'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '4'
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
- version: '5.3'
60
+ version: '6.1'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: activesupport
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  version: '4'
68
68
  - - "<"
69
69
  - !ruby/object:Gem::Version
70
- version: '5.3'
70
+ version: '6.1'
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '4'
78
78
  - - "<"
79
79
  - !ruby/object:Gem::Version
80
- version: '5.3'
80
+ version: '6.1'
81
81
  description: Fluent logger
82
82
  email:
83
83
  - read.eval.print@gmail.com
@@ -100,6 +100,7 @@ files:
100
100
  - gemfiles/rails_5.0.gemfile
101
101
  - gemfiles/rails_5.1.gemfile
102
102
  - gemfiles/rails_5.2.gemfile
103
+ - gemfiles/rails_6.0.gemfile
103
104
  - lib/act-fluent-logger-rails.rb
104
105
  - lib/act-fluent-logger-rails/logger.rb
105
106
  - lib/act-fluent-logger-rails/version.rb
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  version: '0'
126
127
  requirements: []
127
128
  rubyforge_project:
128
- rubygems_version: 2.5.1
129
+ rubygems_version: 2.4.5.1
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: Fluent logger