log_toolbox 1.2.0 → 1.3.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
  SHA256:
3
- metadata.gz: e7a0a82ef30745dbef3c5bc479a0be875fd881b015254b5650ce15c61611595c
4
- data.tar.gz: 797f45b294bdabeaf068df140e3d278dfd20a5b2f23ff684f40d865703bec041
3
+ metadata.gz: cfb310b68412730aaa0bfa5d92a15c8e244486bd58b3123f02ce7e01d4736d66
4
+ data.tar.gz: fc39e75e6e06dd7b81447d8b1d41fe95a1ce82b8fd0d9b61d5cb02be32f1a605
5
5
  SHA512:
6
- metadata.gz: 897098929dea4f4105c1eba591d3a133c33c8faada961f09d1e4dc959fd2f6b86801f69d4f863030bce531a5e9ab99706a84944f4f366604b9a1d55d149e5707
7
- data.tar.gz: 9a2a119b9dcd418e86684678f24c2b0f49a87799a41d52b4593b907ac143b2b652c9984d2106e0d181c9f83f75848bee29f87c6666e5e9ab292ceb1d1933f572
6
+ metadata.gz: 2da7b481ea7dd2c5e496f5e68c8562d89a21e80f97c32fa52439b41f18490bf1c12da1f747720d9e1108425ea6e65d2204304ca02421b114f19e521d434b41dd
7
+ data.tar.gz: c56341160141cc458888d78d33497c84dc8c875e8a5f407580fe1a81fe7931dfee9da38a56be2192ad5a138b54c2aa9a09920fda40688e5474014b1101973e44
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ 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.0] - 2019-07-30
10
+ ### Added
11
+ - Add feature to send log to logstash at stanging and production environment
12
+
9
13
  ## [1.2.0] - 2019-07-24
10
14
  ### Added
11
15
  - Add feature to change log level of your application at running time
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_toolbox (1.2.0)
4
+ log_toolbox (1.3.0)
5
5
  lograge (>= 0.11.1)
6
6
  logstash-event (>= 1.2.02)
7
+ logstash-logger (>= 0.26.1)
7
8
  rails (>= 4.0)
8
9
 
9
10
  GEM
@@ -70,6 +71,8 @@ GEM
70
71
  railties (>= 4)
71
72
  request_store (~> 1.0)
72
73
  logstash-event (1.2.02)
74
+ logstash-logger (0.26.1)
75
+ logstash-event (~> 1.2)
73
76
  loofah (2.2.3)
74
77
  crass (~> 1.0.2)
75
78
  nokogiri (>= 1.5.9)
@@ -1,32 +1,62 @@
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
+
8
10
  def self.configure
9
11
  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
- }
12
+ log_config = LogToolbox::LogrageConfig.new(config)
13
+ if ENV['RAILS_ENV'] == 'development'
14
+ log_config.configure_log_output_stdout
15
+ else
16
+ log_config.configure_log_output_logstash
27
17
  end
28
18
  end
29
- # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
30
19
  end
20
+
21
+ def initialize(config)
22
+ @config = config
23
+ end
24
+
25
+ def configure_log_output_logstash
26
+ config.logger = LogStashLogger.new(type: :udp,
27
+ host: ENV['LOGSTASH_URL'],
28
+ port: ENV['LOGSTASH_PORT'])
29
+ end
30
+
31
+ def configure_log_output_stdout
32
+ return unless ENV['RAILS_LOG_TO_STDOUT'].present?
33
+
34
+ logger = ActiveSupport::Logger.new(STDOUT)
35
+ logger.formatter = config.log_formatter
36
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
37
+ end
38
+
39
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
40
+ def configure_log_format
41
+ config.lograge.enabled = true
42
+ config.lograge.base_controller_class = 'ActionController::API'
43
+ config.lograge.formatter = Lograge::Formatters::Json.new
44
+
45
+ config.lograge.custom_options = lambda do |event|
46
+ {
47
+ activityID: event.payload[:activityID],
48
+ event_at: event.payload[:event_at],
49
+ level: 'INFO',
50
+ service_name: event.payload[:service_name],
51
+ version: event.payload[:version],
52
+ origin_ipv4: event.payload[:origin_ipv4],
53
+ destination_ipv4: event.payload[:destination_ipv4],
54
+ username: event.payload[:username],
55
+ exception_stack: event.payload[:exception_stack],
56
+ response: event.payload[:response]
57
+ }
58
+ end
59
+ end
60
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
31
61
  end
32
62
  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.0'
5
5
  end
data/log_toolbox.gemspec CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'lograge', '>= 0.11.1'
25
25
  spec.add_dependency 'logstash-event', '>= 1.2.02'
26
- spec.add_dependency('rails', ['>= 4.0'])
26
+ spec.add_dependency 'logstash-logger', '>= 0.26.1'
27
+ spec.add_dependency 'rails', ['>= 4.0']
27
28
 
28
29
  spec.add_development_dependency 'bundler'
29
30
  spec.add_development_dependency 'pry'
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.0
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: 2019-07-30 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