log_toolbox 1.3.0 → 1.3.5

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: cfb310b68412730aaa0bfa5d92a15c8e244486bd58b3123f02ce7e01d4736d66
4
- data.tar.gz: fc39e75e6e06dd7b81447d8b1d41fe95a1ce82b8fd0d9b61d5cb02be32f1a605
3
+ metadata.gz: 242002b9bd8b12b831126fdd8a500608149a3f2f32046813308ed58739d042d4
4
+ data.tar.gz: 2f26403b6bcb6aa638634d195da70fdfb3abb30620075bbdce5a79cec6f1042c
5
5
  SHA512:
6
- metadata.gz: 2da7b481ea7dd2c5e496f5e68c8562d89a21e80f97c32fa52439b41f18490bf1c12da1f747720d9e1108425ea6e65d2204304ca02421b114f19e521d434b41dd
7
- data.tar.gz: c56341160141cc458888d78d33497c84dc8c875e8a5f407580fe1a81fe7931dfee9da38a56be2192ad5a138b54c2aa9a09920fda40688e5474014b1101973e44
6
+ metadata.gz: 4cc0b12e1dc369f6f503b6a499fb6005f5a679fc182bc04b36e0d2acb5498ae9bfcf172787416acdf896c0f39231576a67bf48271c853fdb31ff94035e85e274
7
+ data.tar.gz: 9fde6d9099e3bcf904eafe985a991386be622c6ef81a194d0e4118aada76cf76f3c28e860493ca32b6cc7f247b0d9fbcc8a9354879881019cd9f17aaaf29786f
@@ -6,6 +6,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Released] - 2019-05-21
8
8
 
9
+ ## [1.3.5] - 2020-12-04
10
+ ### FIXED
11
+ - Convert buffer_max_items and buffer_max_interval values to integer
12
+
13
+ ## [1.3.4] - 2020-12-03
14
+ ### Added
15
+ - Add settings to buffer_max_items and buffer_max_interval
16
+
17
+ ## [1.3.3] - 2020-11-25
18
+ ### Added
19
+ - Parametrize logstash protocol
20
+ - Refactor request logs
21
+
22
+ ## [1.3.2] - 2020-02-19
23
+ ### Fixed
24
+ - Fixed log simple sending to logstash
25
+
26
+ ## [1.3.1] - 2019-07-30
27
+ ### Fixed
28
+ - Missed log format on posting to logstash
29
+
9
30
  ## [1.3.0] - 2019-07-30
10
31
  ### Added
11
32
  - Add feature to send log to logstash at stanging and production environment
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_toolbox (1.3.0)
4
+ log_toolbox (1.3.5)
5
5
  lograge (>= 0.11.1)
6
6
  logstash-event (>= 1.2.02)
7
7
  logstash-logger (>= 0.26.1)
8
8
  rails (>= 4.0)
9
+ rspec (>= 3.0.0)
10
+ rspec-rails
9
11
 
10
12
  GEM
11
13
  remote: https://rubygems.org/
@@ -81,11 +83,11 @@ GEM
81
83
  marcel (0.3.3)
82
84
  mimemagic (~> 0.3.2)
83
85
  method_source (0.9.2)
84
- mimemagic (0.3.3)
86
+ mimemagic (0.3.5)
85
87
  mini_mime (1.0.2)
86
88
  mini_portile2 (2.4.0)
87
89
  minitest (5.11.3)
88
- nio4r (2.4.0)
90
+ nio4r (2.5.4)
89
91
  nokogiri (1.10.3)
90
92
  mini_portile2 (~> 2.4.0)
91
93
  parallel (1.17.0)
@@ -126,8 +128,12 @@ GEM
126
128
  thor (>= 0.19.0, < 2.0)
127
129
  rainbow (3.0.0)
128
130
  rake (12.3.2)
129
- request_store (1.4.1)
131
+ request_store (1.5.0)
130
132
  rack (>= 1.4)
133
+ rspec (3.8.0)
134
+ rspec-core (~> 3.8.0)
135
+ rspec-expectations (~> 3.8.0)
136
+ rspec-mocks (~> 3.8.0)
131
137
  rspec-core (3.8.2)
132
138
  rspec-support (~> 3.8.0)
133
139
  rspec-expectations (3.8.4)
@@ -155,10 +161,10 @@ GEM
155
161
  ruby-progressbar (1.10.1)
156
162
  shoulda-matchers (3.1.3)
157
163
  activesupport (>= 4.0.0)
158
- sprockets (3.7.2)
164
+ sprockets (4.0.2)
159
165
  concurrent-ruby (~> 1.0)
160
166
  rack (> 1, < 3)
161
- sprockets-rails (3.2.1)
167
+ sprockets-rails (3.2.2)
162
168
  actionpack (>= 4.0)
163
169
  activesupport (>= 4.0)
164
170
  sprockets (>= 3.0.0)
@@ -168,9 +174,9 @@ GEM
168
174
  tzinfo (1.2.5)
169
175
  thread_safe (~> 0.1)
170
176
  unicode-display_width (1.6.0)
171
- websocket-driver (0.7.1)
177
+ websocket-driver (0.7.3)
172
178
  websocket-extensions (>= 0.1.0)
173
- websocket-extensions (0.1.4)
179
+ websocket-extensions (0.1.5)
174
180
 
175
181
  PLATFORMS
176
182
  ruby
data/README.md CHANGED
@@ -22,7 +22,7 @@ $ gem install log_toolbox
22
22
 
23
23
  ## Usage
24
24
 
25
- Create a rails initializer 'config/initializers/lograge.rb' with content
25
+ Add this line at the end of your 'config/application.rb'
26
26
 
27
27
  ```ruby
28
28
  LogToolbox::LogrageConfig.configure
@@ -36,6 +36,14 @@ class ApplicationController < ActionController::API
36
36
  end
37
37
  ```
38
38
 
39
+ Add these keys at your '.env' file
40
+
41
+ ```ruby
42
+ # Logstash
43
+ LOGSTASH_URL=utils-hml.aws.guideinvestimentos.com.br
44
+ LOGSTASH_PORT=5001
45
+ ```
46
+
39
47
  Now your application log was converted to json pattern.
40
48
 
41
49
  ### Log at controller
@@ -8,7 +8,7 @@ pipelines:
8
8
  - gem update bundler
9
9
  - bundle install
10
10
  - gem install rubocop
11
- - rspec -fdoc
11
+ - bundle exec rspec -fdoc
12
12
  - rubocop .
13
13
 
14
14
  branches:
@@ -7,7 +7,7 @@ module LogToolbox
7
7
  'fatal',
8
8
  additional.merge(
9
9
  message: error.try(:message),
10
- exception_stack: error.try(:backtrace),
10
+ backtrace: error.try(:backtrace),
11
11
  status: 500
12
12
  )
13
13
  )
@@ -31,7 +31,7 @@ module LogToolbox
31
31
 
32
32
  private
33
33
 
34
- # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
34
+ # rubocop:disable Metrics/MethodLength
35
35
  def default_log(level)
36
36
  level = 'CRITICAL' if level == 'FATAL'
37
37
  {
@@ -45,7 +45,7 @@ module LogToolbox
45
45
  username: request.headers['Authorization']
46
46
  }
47
47
  end
48
- # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
48
+ # rubocop:enable Metrics/MethodLength
49
49
 
50
50
  def log_pattern(level, log_hash)
51
51
  log = default_log(level.upcase).merge(log_hash)
@@ -12,7 +12,7 @@ module LogToolbox
12
12
  def append_info_to_payload(payload)
13
13
  super
14
14
  payload[:activityID] = request.headers['activityID']
15
- payload[:event_at] = I18n.l(Time.now, format: :timestamp)
15
+ payload[:event_at] = I18n.l(Time.current, format: :timestamp)
16
16
  payload[:service_name] = LogUtil.system_service_name
17
17
  payload[:version] = LogUtil.system_version
18
18
  payload[:origin_ipv4] = request.env['REMOTE_ADDR']
@@ -15,11 +15,15 @@ module LogToolbox
15
15
  log_pattern('info', additional.merge(message: message))
16
16
  end
17
17
 
18
+ def log_debug(message, additional = {})
19
+ log_pattern('debug', additional.merge(message: message))
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def log_pattern(level, log_hash)
21
25
  log = default_log(level.upcase).merge(log_hash)
22
- puts(normalize_hash(log))
26
+ Rails.logger.send(level, normalize_hash(log))
23
27
  end
24
28
 
25
29
  def default_log(level)
@@ -7,9 +7,16 @@ module LogToolbox
7
7
  class LogrageConfig
8
8
  attr_accessor :config
9
9
 
10
+ LOGSTASH_URL = ENV['LOGSTASH_URL']
11
+ LOGSTASH_PORT = ENV['LOGSTASH_PORT']
12
+ LOGSTASH_PROTOCOL = ENV.fetch('LOGSTASH_PROTOCOL', 'udp')
13
+ LOGSTASH_BUFFER_MAX_ITEMS = ENV['LOGSTASH_BUFFER_MAX_ITEMS'].to_i
14
+ LOGSTASH_BUFFER_MAX_INTERVAL = ENV['LOGSTASH_BUFFER_MAX_INTERVAL'].to_i
15
+
10
16
  def self.configure
11
17
  Rails.application.configure do
12
18
  log_config = LogToolbox::LogrageConfig.new(config)
19
+ log_config.configure_log_format
13
20
  if ENV['RAILS_ENV'] == 'development'
14
21
  log_config.configure_log_output_stdout
15
22
  else
@@ -23,15 +30,17 @@ module LogToolbox
23
30
  end
24
31
 
25
32
  def configure_log_output_logstash
26
- config.logger = LogStashLogger.new(type: :udp,
27
- host: ENV['LOGSTASH_URL'],
28
- port: ENV['LOGSTASH_PORT'])
33
+ config.logger = LogStashLogger.new(type: LOGSTASH_PROTOCOL,
34
+ host: LOGSTASH_URL,
35
+ port: LOGSTASH_PORT,
36
+ buffer_max_items: LOGSTASH_BUFFER_MAX_ITEMS || 50,
37
+ buffer_max_interval: LOGSTASH_BUFFER_MAX_INTERVAL || 5)
29
38
  end
30
39
 
31
40
  def configure_log_output_stdout
32
41
  return unless ENV['RAILS_LOG_TO_STDOUT'].present?
33
42
 
34
- logger = ActiveSupport::Logger.new(STDOUT)
43
+ logger = ActiveSupport::Logger.new($stdout)
35
44
  logger.formatter = config.log_formatter
36
45
  config.logger = ActiveSupport::TaggedLogging.new(logger)
37
46
  end
@@ -44,19 +53,23 @@ module LogToolbox
44
53
 
45
54
  config.lograge.custom_options = lambda do |event|
46
55
  {
47
- activityID: event.payload[:activityID],
48
56
  event_at: event.payload[:event_at],
57
+ parameters: event.payload[:params].to_json,
49
58
  level: 'INFO',
50
59
  service_name: event.payload[:service_name],
51
60
  version: event.payload[:version],
52
61
  origin_ipv4: event.payload[:origin_ipv4],
53
62
  destination_ipv4: event.payload[:destination_ipv4],
54
- username: event.payload[:username],
55
- exception_stack: event.payload[:exception_stack],
56
- response: event.payload[:response]
63
+ username: wso2_user_name(event.payload[:headers][:HTTP_USER_IDENTIFIER])
57
64
  }
58
65
  end
59
66
  end
60
67
  # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
68
+
69
+ def wso2_user_name(http_user_identifier)
70
+ return nil unless http_user_identifier.is_a? String
71
+
72
+ http_user_identifier ? JSON.parse(Base64.decode64(http_user_identifier))['user_name'] : nil
73
+ end
61
74
  end
62
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogToolbox
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.5'
5
5
  end
@@ -4,17 +4,19 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'log_toolbox/version'
6
6
 
7
+ # rubocop:disable Metrics/BlockLength
7
8
  Gem::Specification.new do |spec|
8
- spec.name = 'log_toolbox'
9
- spec.version = LogToolbox::VERSION
10
- spec.authors = ['Caio Almeida']
11
- spec.email = ['cbalmeida@guide.com.br']
9
+ spec.name = 'log_toolbox'
10
+ spec.version = LogToolbox::VERSION
11
+ spec.authors = ['Caio Almeida']
12
+ spec.email = ['cbalmeida@guide.com.br']
12
13
 
13
- spec.summary = 'Guide default gem for ruby application logging'
14
- spec.homepage = 'http://bitbucket.org/guideinvestimentos/log_toolbox'
15
- spec.license = 'Guide'
14
+ spec.required_ruby_version = '>= 2.4.0'
15
+ spec.summary = 'Guide default gem for ruby application logging'
16
+ spec.homepage = 'http://bitbucket.org/guideinvestimentos/log_toolbox'
17
+ spec.license = 'Guide'
16
18
 
17
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
20
  `git ls-files -z`.split("\x0").reject do |f|
19
21
  f.match(%r{^(test|spec|features)/})
20
22
  end
@@ -25,6 +27,8 @@ Gem::Specification.new do |spec|
25
27
  spec.add_dependency 'logstash-event', '>= 1.2.02'
26
28
  spec.add_dependency 'logstash-logger', '>= 0.26.1'
27
29
  spec.add_dependency 'rails', ['>= 4.0']
30
+ spec.add_dependency 'rspec', '>= 3.0.0'
31
+ spec.add_dependency 'rspec-rails'
28
32
 
29
33
  spec.add_development_dependency 'bundler'
30
34
  spec.add_development_dependency 'pry'
@@ -34,3 +38,4 @@ Gem::Specification.new do |spec|
34
38
  spec.add_development_dependency 'rubocop'
35
39
  spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
36
40
  end
41
+ # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Almeida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-30 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lograge
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: bundler
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
234
  requirements:
207
235
  - - ">="
208
236
  - !ruby/object:Gem::Version
209
- version: '0'
237
+ version: 2.4.0
210
238
  required_rubygems_version: !ruby/object:Gem::Requirement
211
239
  requirements:
212
240
  - - ">="