influxdb-logger 1.0.2 → 1.0.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
2
  SHA1:
3
- metadata.gz: cd80eaf9eda418f4e29e848e43c8fdc27af5313d
4
- data.tar.gz: aea9e2e75e2cf55dad07ed6c7416c78f0eec351b
3
+ metadata.gz: 8b05d8b6706111f2fca5db10879f26ce106aa81b
4
+ data.tar.gz: f486822bc9d4c99f7837c8dfc6d0ee760c240e48
5
5
  SHA512:
6
- metadata.gz: ebdebe6c27c0cd8c7165fdf71e42f5fc416aa6573d85129ee2ed72734ed9eba0fd7e09cb8f368912859524b009d5251ae3470a102d9e239bfa7110d06c3b82c4
7
- data.tar.gz: b9014899996b8f54788062748c91f1171ab290a63b674c222f67b87a344c1755c4f6be31bef47e406e08c7c7d2d53bb3a7e1207d79c3ae78b6952beedda45edb
6
+ metadata.gz: e438029412859abae4811a40d1982ff86f24f8faa762f37f4f653666109dbeea1130635146a5a6df6254870267345ffe862d04255f7616464efd36ae0463abf4
7
+ data.tar.gz: a46e990537873512fa206aa0de0de1eff7121fc0db29b2f86c189784e9fe0fc3038fb9b7e5f1a2508aa15c8c6152d24e5d69e938440b61434cd8b341e2b85630
@@ -33,22 +33,22 @@ class Time
33
33
  end
34
34
  end
35
35
 
36
- module InfluxdbLogger
37
- def log_to_file(message) # for test
38
- open("#{Rails.root}/log/my.log", 'a') { |f|
39
- f.puts message.inspect
40
- }
41
- end
36
+ def log_to_file(message) # for test
37
+ open("#{Rails.root}/log/my.log", 'a') { |f|
38
+ f.puts message.inspect
39
+ }
40
+ end
42
41
 
42
+ module InfluxdbLogger
43
43
  module Logger
44
-
45
44
  # Severity label for logging. (max 5 char)
46
45
  SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
47
46
 
48
- def self.new(async: true, log_tags: {}, settings: {}, batch_size: 1000, interval: 1000)
49
- Rails.application.config.log_tags = log_tags.values
47
+ def self.new(async: true, tags: {}, fields: {}, settings: {}, batch_size: 1000, interval: 1000)
48
+ all_tags = tags.values + fields.values
49
+ Rails.application.config.log_tags = all_tags
50
50
  if Rails.application.config.respond_to?(:action_cable)
51
- Rails.application.config.action_cable.log_tags = log_tags.values.map do |x|
51
+ Rails.application.config.action_cable.log_tags = all_tags.map do |x|
52
52
  case
53
53
  when x.respond_to?(:call)
54
54
  x
@@ -69,7 +69,7 @@ module InfluxdbLogger
69
69
  settings[:async] = async
70
70
 
71
71
  level = SEV_LABEL.index(Rails.application.config.log_level.to_s.upcase)
72
- logger = InfluxdbLogger::InnerLogger.new(settings, level, log_tags)
72
+ logger = InfluxdbLogger::InnerLogger.new(settings, level, tags, fields)
73
73
  logger = ActiveSupport::TaggedLogging.new(logger)
74
74
  logger.extend self
75
75
  end
@@ -100,7 +100,7 @@ module InfluxdbLogger
100
100
  end
101
101
 
102
102
  class InnerLogger < ActiveSupport::Logger
103
- def initialize(options, level, log_tags)
103
+ def initialize(options, level, tags, fields)
104
104
  self.level = level
105
105
  @messages_type = (options[:messages_type] || :array).to_sym
106
106
  @tag = options[:tag]
@@ -122,7 +122,8 @@ module InfluxdbLogger
122
122
 
123
123
  @severity = 0
124
124
  @messages = []
125
- @log_tags = log_tags
125
+ @all_tags = tags.merge(fields)
126
+ @fields = fields
126
127
  after_initialize if respond_to? :after_initialize
127
128
  end
128
129
 
@@ -183,7 +184,7 @@ module InfluxdbLogger
183
184
  tags = @global_tags.clone
184
185
 
185
186
  if @tags
186
- @log_tags.keys.zip(@tags).each do |k, v|
187
+ @all_tags.keys.zip(@tags).each do |k, v|
187
188
  tags[k] = v
188
189
  end
189
190
  end
@@ -191,8 +192,8 @@ module InfluxdbLogger
191
192
  message = {
192
193
  series: @series,
193
194
  timestamp: Time.now.to_precision(@time_precision),
194
- tags: tags,
195
- values: values.merge({
195
+ tags: tags.except(@fields.keys),
196
+ values: values.merge(tags.slice(@fields.keys)).merge({
196
197
  severity: format_severity(@severity)
197
198
  }).transform_values {|value|
198
199
  case value
@@ -1,3 +1,3 @@
1
1
  module InfluxdbLogger
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/spec/logger_spec.rb CHANGED
@@ -51,7 +51,7 @@ describe InfluxdbLogger::Logger do
51
51
 
52
52
  let(:series) { 'Request' }
53
53
 
54
- let(:log_tags) {
54
+ let(:tags) {
55
55
  {
56
56
  uuid: :uuid,
57
57
  foo: ->(request) { 'foo_value' }
@@ -71,7 +71,7 @@ describe InfluxdbLogger::Logger do
71
71
  }
72
72
 
73
73
  let(:logger) {
74
- InfluxdbLogger::Logger.new(log_tags: log_tags, settings: settings)
74
+ InfluxdbLogger::Logger.new(tags: tags, settings: settings)
75
75
  }
76
76
 
77
77
  let(:request) {
@@ -81,9 +81,9 @@ describe InfluxdbLogger::Logger do
81
81
  describe 'logging' do
82
82
 
83
83
  describe 'basic' do
84
- it 'info' do
84
+ it 'info', now: true do
85
85
  # see Rails::Rack::compute_tags
86
- tags = log_tags.values.collect do |tag|
86
+ tag_values = tags.values.collect do |tag|
87
87
  case tag
88
88
  when Proc
89
89
  tag.call(request)
@@ -94,7 +94,7 @@ describe InfluxdbLogger::Logger do
94
94
  end
95
95
  end
96
96
  logger[:abc] = 'xyz'
97
- logger.tagged(tags) { logger.info('hello') }
97
+ logger.tagged(tag_values) { logger.info('hello') }
98
98
  expect(@my_logger.log).to eq(
99
99
  [{
100
100
  series: series,
@@ -111,7 +111,7 @@ describe InfluxdbLogger::Logger do
111
111
  }
112
112
  }])
113
113
  @my_logger.clear
114
- logger.tagged(tags) { logger.info('world'); logger.info('bye') }
114
+ logger.tagged(tag_values) { logger.info('world'); logger.info('bye') }
115
115
  expect(@my_logger.log).to eq(
116
116
  [{
117
117
  series: series,
@@ -215,7 +215,7 @@ describe InfluxdbLogger::Logger do
215
215
  end
216
216
  end
217
217
 
218
- describe 'batch size', now: true do
218
+ describe 'batch size' do
219
219
  it 'inner logger write_points after every two messages if batch_size is set to 2' do
220
220
  logger = InfluxdbLogger::Logger.new(settings: settings, batch_size: 2)
221
221
  logger.info('message 1')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rallets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec