log_toolbox 1.2.0 → 1.3.4

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: e7a0a82ef30745dbef3c5bc479a0be875fd881b015254b5650ce15c61611595c
4
- data.tar.gz: 797f45b294bdabeaf068df140e3d278dfd20a5b2f23ff684f40d865703bec041
3
+ metadata.gz: 5ac8156b11e49224b6a2505694346bee18bb52f0672befb14e6e711cff84b45d
4
+ data.tar.gz: 5319f54b73100e5bc36ee754f8e62732fa6ded6560b73c97a93bdd72e4c1f3df
5
5
  SHA512:
6
- metadata.gz: 897098929dea4f4105c1eba591d3a133c33c8faada961f09d1e4dc959fd2f6b86801f69d4f863030bce531a5e9ab99706a84944f4f366604b9a1d55d149e5707
7
- data.tar.gz: 9a2a119b9dcd418e86684678f24c2b0f49a87799a41d52b4593b907ac143b2b652c9984d2106e0d181c9f83f75848bee29f87c6666e5e9ab292ceb1d1933f572
6
+ metadata.gz: 97d815d439efa23b6ac48b6aaaa7b977f5af22996460ab922fbf07cf3a99c65211e7ef530a59b3d378582d52f5ae9649a39ad374f31eda8d39b76550ef6ac319
7
+ data.tar.gz: f8d09ba573af4f0f7ed1cf1c65900c39a0d7c3fb67e15cb0071f5c1302e305a22827afc2149156f357f81454a0dc0b80d108ce883a4f239cc4c616de45d0aabf
@@ -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.4] - 2020-12-03
10
+ ### Addd
11
+ - Add settings to buffer_max_items and buffer_max_interval
12
+
13
+ ## [1.3.3] - 2020-11-25
14
+ ### Added
15
+ - Parametrize logstash protocol
16
+ - Refactor request logs
17
+
18
+ ## [1.3.2] - 2020-02-19
19
+ ### Fixed
20
+ - Fixed log simple sending to logstash
21
+
22
+ ## [1.3.1] - 2019-07-30
23
+ ### Fixed
24
+ - Missed log format on posting to logstash
25
+
26
+ ## [1.3.0] - 2019-07-30
27
+ ### Added
28
+ - Add feature to send log to logstash at stanging and production environment
29
+
9
30
  ## [1.2.0] - 2019-07-24
10
31
  ### Added
11
32
  - Add feature to change log level of your application at running time
@@ -1,10 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_toolbox (1.2.0)
4
+ log_toolbox (1.3.3)
5
5
  lograge (>= 0.11.1)
6
6
  logstash-event (>= 1.2.02)
7
+ logstash-logger (>= 0.26.1)
7
8
  rails (>= 4.0)
9
+ rspec (>= 3.0.0)
10
+ rspec-rails
8
11
 
9
12
  GEM
10
13
  remote: https://rubygems.org/
@@ -70,6 +73,8 @@ GEM
70
73
  railties (>= 4)
71
74
  request_store (~> 1.0)
72
75
  logstash-event (1.2.02)
76
+ logstash-logger (0.26.1)
77
+ logstash-event (~> 1.2)
73
78
  loofah (2.2.3)
74
79
  crass (~> 1.0.2)
75
80
  nokogiri (>= 1.5.9)
@@ -78,11 +83,11 @@ GEM
78
83
  marcel (0.3.3)
79
84
  mimemagic (~> 0.3.2)
80
85
  method_source (0.9.2)
81
- mimemagic (0.3.3)
86
+ mimemagic (0.3.5)
82
87
  mini_mime (1.0.2)
83
88
  mini_portile2 (2.4.0)
84
89
  minitest (5.11.3)
85
- nio4r (2.4.0)
90
+ nio4r (2.5.4)
86
91
  nokogiri (1.10.3)
87
92
  mini_portile2 (~> 2.4.0)
88
93
  parallel (1.17.0)
@@ -123,8 +128,12 @@ GEM
123
128
  thor (>= 0.19.0, < 2.0)
124
129
  rainbow (3.0.0)
125
130
  rake (12.3.2)
126
- request_store (1.4.1)
131
+ request_store (1.5.0)
127
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)
128
137
  rspec-core (3.8.2)
129
138
  rspec-support (~> 3.8.0)
130
139
  rspec-expectations (3.8.4)
@@ -152,10 +161,10 @@ GEM
152
161
  ruby-progressbar (1.10.1)
153
162
  shoulda-matchers (3.1.3)
154
163
  activesupport (>= 4.0.0)
155
- sprockets (3.7.2)
164
+ sprockets (4.0.2)
156
165
  concurrent-ruby (~> 1.0)
157
166
  rack (> 1, < 3)
158
- sprockets-rails (3.2.1)
167
+ sprockets-rails (3.2.2)
159
168
  actionpack (>= 4.0)
160
169
  activesupport (>= 4.0)
161
170
  sprockets (>= 3.0.0)
@@ -165,9 +174,9 @@ GEM
165
174
  tzinfo (1.2.5)
166
175
  thread_safe (~> 0.1)
167
176
  unicode-display_width (1.6.0)
168
- websocket-driver (0.7.1)
177
+ websocket-driver (0.7.3)
169
178
  websocket-extensions (>= 0.1.0)
170
- websocket-extensions (0.1.4)
179
+ websocket-extensions (0.1.5)
171
180
 
172
181
  PLATFORMS
173
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)
@@ -1,32 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'lograge'
4
+ require 'logstash-logger'
4
5
 
5
6
  module LogToolbox
6
7
  class LogrageConfig
7
- # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
8
+ attr_accessor :config
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']
14
+ LOGSTASH_BUFFER_MAX_INTERVAL = ENV['LOGSTASH_BUFFER_MAX_INTERVAL']
15
+
8
16
  def self.configure
9
17
  Rails.application.configure do
10
- config.lograge.enabled = true
11
- config.lograge.base_controller_class = 'ActionController::API'
12
- config.lograge.formatter = Lograge::Formatters::Json.new
13
-
14
- config.lograge.custom_options = lambda do |event|
15
- {
16
- activityID: event.payload[:activityID],
17
- event_at: event.payload[:event_at],
18
- level: 'INFO',
19
- service_name: event.payload[:service_name],
20
- version: event.payload[:version],
21
- origin_ipv4: event.payload[:origin_ipv4],
22
- destination_ipv4: event.payload[:destination_ipv4],
23
- username: event.payload[:username],
24
- exception_stack: event.payload[:exception_stack],
25
- response: event.payload[:response]
26
- }
18
+ log_config = LogToolbox::LogrageConfig.new(config)
19
+ log_config.configure_log_format
20
+ if ENV['RAILS_ENV'] == 'development'
21
+ log_config.configure_log_output_stdout
22
+ else
23
+ log_config.configure_log_output_logstash
27
24
  end
28
25
  end
29
- # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
26
+ end
27
+
28
+ def initialize(config)
29
+ @config = config
30
+ end
31
+
32
+ def configure_log_output_logstash
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)
38
+ end
39
+
40
+ def configure_log_output_stdout
41
+ return unless ENV['RAILS_LOG_TO_STDOUT'].present?
42
+
43
+ logger = ActiveSupport::Logger.new($stdout)
44
+ logger.formatter = config.log_formatter
45
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
46
+ end
47
+
48
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
49
+ def configure_log_format
50
+ config.lograge.enabled = true
51
+ config.lograge.base_controller_class = 'ActionController::API'
52
+ config.lograge.formatter = Lograge::Formatters::Json.new
53
+
54
+ config.lograge.custom_options = lambda do |event|
55
+ {
56
+ event_at: event.payload[:event_at],
57
+ parameters: event.payload[:params].to_json,
58
+ level: 'INFO',
59
+ service_name: event.payload[:service_name],
60
+ version: event.payload[:version],
61
+ origin_ipv4: event.payload[:origin_ipv4],
62
+ destination_ipv4: event.payload[:destination_ipv4],
63
+ username: wso2_user_name(event.payload[:headers][:HTTP_USER_IDENTIFIER])
64
+ }
65
+ end
66
+ end
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
30
73
  end
31
74
  end
32
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogToolbox
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.4'
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
@@ -23,7 +25,10 @@ Gem::Specification.new do |spec|
23
25
 
24
26
  spec.add_dependency 'lograge', '>= 0.11.1'
25
27
  spec.add_dependency 'logstash-event', '>= 1.2.02'
26
- spec.add_dependency('rails', ['>= 4.0'])
28
+ spec.add_dependency 'logstash-logger', '>= 0.26.1'
29
+ spec.add_dependency 'rails', ['>= 4.0']
30
+ spec.add_dependency 'rspec', '>= 3.0.0'
31
+ spec.add_dependency 'rspec-rails'
27
32
 
28
33
  spec.add_development_dependency 'bundler'
29
34
  spec.add_development_dependency 'pry'
@@ -33,3 +38,4 @@ Gem::Specification.new do |spec|
33
38
  spec.add_development_dependency 'rubocop'
34
39
  spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
35
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.2.0
4
+ version: 1.3.4
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-26 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
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.02
41
+ - !ruby/object:Gem::Dependency
42
+ name: logstash-logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.26.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.26.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rails
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
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'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: bundler
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
234
  requirements:
193
235
  - - ">="
194
236
  - !ruby/object:Gem::Version
195
- version: '0'
237
+ version: 2.4.0
196
238
  required_rubygems_version: !ruby/object:Gem::Requirement
197
239
  requirements:
198
240
  - - ">="