act-fluent-logger-rails 0.5.0 → 0.6.3

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
- SHA1:
3
- metadata.gz: 125a872f83e8ef5c46ca1ca293b1365fcb3aed52
4
- data.tar.gz: bea7ea99906b406bfda4945cd0683c0e69c61638
2
+ SHA256:
3
+ metadata.gz: f263d124e7851ae0d53b5c1d5c7fb4804cd948151464e98e2373300467495f2b
4
+ data.tar.gz: e99b7d0c656a6bb4eeb1cae6d8909ebde1564f0e90a3c115d03c7e282db6adc3
5
5
  SHA512:
6
- metadata.gz: d2d70096552e8e57783d48c0c055b9528648196aa8ae3863d54aae716c6976b2ab758a2058247df4ed58e3f23d7a6f71e251484cd85c6c0d0fede2694609089c
7
- data.tar.gz: 7f6b11895029ade7a9e2a80d5d4934a252f3f915f27878e22a705307c9d11daaba9790b07fc2619c55eb09af2b0ff8a598aa3695bb5e33c5a487ed4c1ac70a2c
6
+ metadata.gz: 02d7b6e3bc21c6b04664bf1a8dc3378ac45e9867dfd5406219a050f7b14251c81282ca3b549a9fedcf88fee15498f14af089583eb5dc9edf07a02c786b03c296
7
+ data.tar.gz: 6a86c3ecb7be63f7e318d257f484f2e5afc1c3694ec5b8fab87a0b72a289ab496ac3fad0724387fdb44be6b0c680576deb834b0e651d04a12aa4c04e10d6265c
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /vendor
8
8
  Gemfile.lock
9
9
  gemfiles/*.lock
10
+ gemfiles/vendor
10
11
  InstalledFiles
11
12
  _yardoc
12
13
  coverage
data/.travis.yml CHANGED
@@ -1,30 +1,25 @@
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
- - 2.1.10
4
- - 2.2.10
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
6
+ - 2.4.10
7
+ - 2.5.8
8
+ - 2.6.6
9
+ - 2.7.2
10
+ - 3.0.0-preview2
8
11
  gemfile:
9
- - gemfiles/rails_4.0.gemfile
10
- - gemfiles/rails_4.1.gemfile
11
- - gemfiles/rails_4.2.gemfile
12
12
  - gemfiles/rails_5.0.gemfile
13
13
  - gemfiles/rails_5.1.gemfile
14
14
  - gemfiles/rails_5.2.gemfile
15
+ - gemfiles/rails_6.0.gemfile
16
+ - gemfiles/rails_6.1.gemfile
15
17
  matrix:
16
18
  exclude:
17
- - rvm: 2.1.10
18
- gemfile: gemfiles/rails_5.0.gemfile
19
- - rvm: 2.1.10
20
- gemfile: gemfiles/rails_5.1.gemfile
21
- - rvm: 2.1.10
22
- gemfile: gemfiles/rails_5.2.gemfile
23
- - rvm: 2.4.4
24
- gemfile: gemfiles/rails_4.0.gemfile
25
- - rvm: 2.4.4
26
- gemfile: gemfiles/rails_4.1.gemfile
27
- - rvm: 2.5.1
28
- gemfile: gemfiles/rails_4.0.gemfile
29
- - rvm: 2.5.1
30
- gemfile: gemfiles/rails_4.1.gemfile
19
+ - rvm: 2.4.10
20
+ gemfile: gemfiles/rails_6.0.gemfile
21
+ - rvm: 2.4.10
22
+ gemfile: gemfiles/rails_6.1.gemfile
23
+ jobs:
24
+ allow_failures:
25
+ - rvm: 3.0.0-preview2
data/Appraisals CHANGED
@@ -1,18 +1,3 @@
1
- appraise 'rails-4.0' do
2
- gem 'railties', '4.0.13'
3
- gem 'activesupport', '4.0.13'
4
- end
5
-
6
- appraise 'rails-4.1' do
7
- gem 'railties', '4.1.16'
8
- gem 'activesupport', '4.1.16'
9
- end
10
-
11
- appraise 'rails-4.2' do
12
- gem 'railties', '4.2.8'
13
- gem 'activesupport', '4.2.8'
14
- end
15
-
16
1
  appraise 'rails-5.0' do
17
2
  gem 'railties', '5.0.2'
18
3
  gem 'activesupport', '5.0.2'
@@ -27,3 +12,8 @@ appraise 'rails-5.2' do
27
12
  gem 'railties', '5.2.0'
28
13
  gem 'activesupport', '5.2.0'
29
14
  end
15
+
16
+ appraise 'rails-6.0' do
17
+ gem 'railties', '6.0.0.beta2'
18
+ gem 'activesupport', '6.0.0.beta2'
19
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.6.3 / Mar 22 2020
2
+ * Support tls_options #63
3
+
4
+ ## 0.6.2 / Jan 8 2020
5
+ * Rails 6.1
6
+
7
+ ## 0.6.1 / Jan 8 2020
8
+ * Fix warning printed when use Rails 6
9
+
10
+ ## 0.6.0 / Nov 23 2019
11
+
12
+ * Rails 6
13
+ * Make Thread Safe
14
+
1
15
  ## 0.5.0 / April 29 2017
2
16
 
3
17
  * 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
 
@@ -89,6 +89,9 @@ Don't use config.log_tags.
89
89
  2013-01-18T15:04:50+09:00 foo {"messages":["Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900","Processing by TopController#index as HTML","Completed 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"severity":"INFO"}
90
90
  ```
91
91
  * severity_key: The key of severity(DEBUG, INFO, WARN, ERROR).
92
+ * tls_options: A hash of tls options compatible with [fluent-logger-ruby](https://github.com/fluent/fluent-logger-ruby#tls-setting). The simplest being:
93
+ <pre>tls_options:
94
+ use_default_ca: true</pre>
92
95
 
93
96
  You can add any tags at run time.
94
97
 
@@ -113,3 +116,10 @@ ActFluentLoggerRails::Logger.new(flush_immediately: true)
113
116
  3. Commit your changes (`git commit -am 'Add some feature'`)
114
117
  4. Push to the branch (`git push origin my-new-feature`)
115
118
  5. Create new Pull Request
119
+
120
+ ## How to run test with appraisal
121
+ ```
122
+ gem install appraisal
123
+ bundle exec appraisal bundle
124
+ bundle exec appraisal rake
125
+ ```
@@ -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.2"
24
+ gem.add_runtime_dependency "activesupport", ">= 4", "< 6.2"
25
25
  end
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "railties", "4.0.13"
7
- gem "activesupport", "4.0.13"
6
+ gem "railties", "6.0.3.4"
7
+ gem "activesupport", "6.0.3.4"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "railties", "4.2.8"
7
- gem "activesupport", "4.2.8"
6
+ gem "railties", "6.1.0"
7
+ gem "activesupport", "6.1.0"
8
8
 
9
9
  gemspec path: "../"
@@ -2,6 +2,7 @@ require 'fluent-logger'
2
2
  require 'active_support/core_ext'
3
3
  require 'uri'
4
4
  require 'cgi'
5
+ require 'rails/version'
5
6
 
6
7
  module ActFluentLoggerRails
7
8
 
@@ -40,6 +41,7 @@ module ActFluentLoggerRails
40
41
  nanosecond_precision: fluent_config['nanosecond_precision'],
41
42
  messages_type: fluent_config['messages_type'],
42
43
  severity_key: fluent_config['severity_key'],
44
+ tls_options: fluent_config['tls_options']&.transform_keys { |k| k.to_sym }
43
45
  }
44
46
  end
45
47
 
@@ -66,7 +68,8 @@ module ActFluentLoggerRails
66
68
  end
67
69
 
68
70
  def tagged(*tags)
69
- @tags = tags.flatten
71
+ @tags_thread_key ||= "fluentd_tagged_logging_tags:#{object_id}".freeze
72
+ Thread.current[@tags_thread_key] = tags.flatten
70
73
  yield self
71
74
  ensure
72
75
  flush
@@ -84,12 +87,11 @@ module ActFluentLoggerRails
84
87
  @severity_key = (options[:severity_key] || :severity).to_sym
85
88
  @flush_immediately = options[:flush_immediately]
86
89
  logger_opts = {host: host, port: port, nanosecond_precision: nanosecond_precision}
90
+ logger_opts[:tls_options] = options[:tls_options] unless options[:tls_options].nil?
87
91
  @fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, logger_opts)
88
92
  @severity = 0
89
- @messages = []
90
93
  @log_tags = log_tags
91
- @map = {}
92
- after_initialize if respond_to? :after_initialize
94
+ after_initialize if respond_to?(:after_initialize) && Rails::VERSION::MAJOR < 6
93
95
  end
94
96
 
95
97
  def add(severity, message = nil, progname = nil, &block)
@@ -115,41 +117,55 @@ module ActFluentLoggerRails
115
117
  end
116
118
 
117
119
  if message.encoding == Encoding::UTF_8
118
- @messages << message
120
+ logger_messages << message
119
121
  else
120
- @messages << message.dup.force_encoding(Encoding::UTF_8)
122
+ logger_messages << message.dup.force_encoding(Encoding::UTF_8)
121
123
  end
122
124
 
123
125
  flush if @flush_immediately
124
126
  end
125
127
 
126
128
  def [](key)
127
- @map[key]
129
+ map[key]
128
130
  end
129
131
 
130
132
  def []=(key, value)
131
- @map[key] = value
133
+ map[key] = value
132
134
  end
133
135
 
134
136
  def flush
135
- return if @messages.empty?
137
+ return if logger_messages.empty?
136
138
  messages = if @messages_type == :string
137
- @messages.join("\n")
139
+ logger_messages.join("\n")
138
140
  else
139
- @messages
141
+ logger_messages
140
142
  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)
143
+ map[:messages] = messages
144
+ map[@severity_key] = format_severity(@severity)
145
+ add_tags
146
+
147
+ @fluent_logger.post(@tag, map)
149
148
  @severity = 0
150
- @messages.clear
151
- @tags = nil
152
- @map.clear
149
+ logger_messages.clear
150
+ Thread.current[@tags_thread_key] = nil if @tags_thread_key
151
+ map.clear
152
+ end
153
+
154
+ def add_tags
155
+ return unless @tags_thread_key && Thread.current.key?(@tags_thread_key)
156
+ @log_tags.keys.zip(Thread.current[@tags_thread_key]).each do |k, v|
157
+ map[k] = v
158
+ end
159
+ end
160
+
161
+ def logger_messages
162
+ @messages_thread_key ||= "fluentd_logger_messages:#{object_id}".freeze
163
+ Thread.current[@messages_thread_key] ||= []
164
+ end
165
+
166
+ def map
167
+ @map_thread_key ||= "fluentd_logger_map:#{object_id}".freeze
168
+ Thread.current[@map_thread_key] ||= {}
153
169
  end
154
170
 
155
171
  def close
@@ -1,3 +1,3 @@
1
1
  module ActFluentLoggerRails
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.3"
3
3
  end
data/spec/logger_spec.rb CHANGED
@@ -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)
@@ -130,6 +162,43 @@ EOF
130
162
  end
131
163
  end
132
164
 
165
+ describe 'tls_options' do
166
+ context 'does not has key' do
167
+ before do
168
+ File.open(@config_file.path, 'w') do |f|
169
+ f.puts <<EOF
170
+ test:
171
+ fluent_host: '127.0.0.1'
172
+ fluent_port: 24224
173
+ tag: 'foo'
174
+ EOF
175
+ end
176
+ end
177
+ it do
178
+ expect(::Fluent::Logger::FluentLogger).not_to receive(:new).with(nil, hash_including(tls_options: { use_default_ca: true }))
179
+ logger
180
+ end
181
+ end
182
+ context 'has key' do
183
+ before do
184
+ File.open(@config_file.path, 'w') do |f|
185
+ f.puts <<EOF
186
+ test:
187
+ fluent_host: '127.0.0.1'
188
+ fluent_port: 24224
189
+ tag: 'foo'
190
+ tls_options:
191
+ use_default_ca: true
192
+ EOF
193
+ end
194
+ end
195
+ it do
196
+ expect(::Fluent::Logger::FluentLogger).to receive(:new).with(nil, hash_including(tls_options: { use_default_ca: true }))
197
+ logger
198
+ end
199
+ end
200
+ end
201
+
133
202
  describe 'severity_key' do
134
203
  describe 'not specified' do
135
204
  it 'severity' do
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAHARA Yoshinori
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2021-03-26 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.2'
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.2'
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.2'
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.2'
81
81
  description: Fluent logger
82
82
  email:
83
83
  - read.eval.print@gmail.com
@@ -94,12 +94,11 @@ files:
94
94
  - README.md
95
95
  - Rakefile
96
96
  - act-fluent-logger-rails.gemspec
97
- - gemfiles/rails_4.0.gemfile
98
- - gemfiles/rails_4.1.gemfile
99
- - gemfiles/rails_4.2.gemfile
100
97
  - gemfiles/rails_5.0.gemfile
101
98
  - gemfiles/rails_5.1.gemfile
102
99
  - gemfiles/rails_5.2.gemfile
100
+ - gemfiles/rails_6.0.gemfile
101
+ - gemfiles/rails_6.1.gemfile
103
102
  - lib/act-fluent-logger-rails.rb
104
103
  - lib/act-fluent-logger-rails/logger.rb
105
104
  - lib/act-fluent-logger-rails/version.rb
@@ -109,7 +108,7 @@ homepage: https://github.com/actindi/act-fluent-logger-rails
109
108
  licenses:
110
109
  - MIT
111
110
  metadata: {}
112
- post_install_message:
111
+ post_install_message:
113
112
  rdoc_options: []
114
113
  require_paths:
115
114
  - lib
@@ -124,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
123
  - !ruby/object:Gem::Version
125
124
  version: '0'
126
125
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.5.1
129
- signing_key:
126
+ rubygems_version: 3.2.3
127
+ signing_key:
130
128
  specification_version: 4
131
129
  summary: Fluent logger
132
130
  test_files:
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "railties", "4.1.16"
7
- gem "activesupport", "4.1.16"
8
-
9
- gemspec path: "../"