md-logstasher 1.1.0 → 1.4.1

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: caa8c203cdf135bf92e27bfca4064949758143c3
4
- data.tar.gz: 98ee851c3e42f83a2c4da5826affa3a1fc1c5ad2
2
+ SHA256:
3
+ metadata.gz: b6d718c5b30fe09e6735c5da021eda006340fdef09dc6a5b251ab6d8a273429b
4
+ data.tar.gz: 35bf7d80f1ce2d8d736de8d47bdd8f00e2ea3579992f057e10e651d9290e1f28
5
5
  SHA512:
6
- metadata.gz: fbcabec619855beaf57346e6ecd42b41ae8ba487ece014e7c34b047bc83c8b12efeb6d0a1e116ae427b407d6d0f59aef40067b1e0b0d3e5a38c47685b7a2ca12
7
- data.tar.gz: 8830d3f59e199d1c31d8226755093b9dfcefb8401d38c9058d0bac828274785e21c81030a5f3a691362d8afd301fc24534b111efec901d71835fa031a135a4d3
6
+ metadata.gz: c7e667ea8187888cc4c7662b6868584a1d829ef878f9c0a949e716cf59093141a9f8f29bd659a933ee1c6ce69f422142f351125515be264cfb32de33e9164994
7
+ data.tar.gz: e167c08b5eaef0ea61e63df8e666974617684ea6a938fb13f44e62aafd9a5d157de4e1d2f3b05568e1186aa4be5160130a479fa0449a6169ffec98ea7bad905e
@@ -0,0 +1,40 @@
1
+ # simple UDP logger
2
+
3
+ require 'logstasher/device'
4
+ require 'socket'
5
+
6
+
7
+ module LogStasher
8
+ module Device
9
+ class UDP
10
+ include ::LogStasher::Device
11
+
12
+ attr_reader :options, :socket
13
+
14
+ def initialize(options = {})
15
+ @options = default_options.merge(stringify_keys(options))
16
+ @socket = UDPSocket.new
17
+ end
18
+
19
+ def close
20
+ @socket.close
21
+ end
22
+
23
+ def write(log)
24
+ @socket.send(log, 0, options['hostname'], options['port'])
25
+ end
26
+
27
+ private
28
+
29
+ def default_options
30
+ {
31
+ 'hostname' => '127.0.0.1',
32
+ 'port' => 31459,
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+
@@ -11,6 +11,11 @@ module LogStasher
11
11
  when "syslog", :syslog then
12
12
  require 'logstasher/device/syslog'
13
13
  ::LogStasher::Device::Syslog.new(config)
14
+ when "udp", :udp then
15
+ require 'logstasher/device/udp'
16
+ ::LogStasher::Device::UDP.new(config)
17
+ when "stdout", :stdout then
18
+ $stdout
14
19
  else
15
20
  fail ArgumentError, "Unknown type: #{type}"
16
21
  end
@@ -21,7 +21,6 @@ module LogStasher
21
21
  payload = event.payload
22
22
  tags = extract_tags(payload)
23
23
  fields = extract_request(payload)
24
-
25
24
  fields.merge! extract_status(payload)
26
25
  fields.merge! runtimes(event)
27
26
  fields.merge! location
@@ -52,15 +51,19 @@ module LogStasher
52
51
  end
53
52
 
54
53
  def extract_request(payload)
55
- {
54
+ result = {
56
55
  :action => payload[:action],
57
56
  :controller => payload[:controller],
58
57
  :format => extract_format(payload),
59
58
  :ip => request.remote_ip,
59
+ :request_id => request.env["action_dispatch.request_id"],
60
60
  :method => payload[:method],
61
61
  :path => extract_path(payload),
62
62
  :route => "#{payload[:controller]}##{payload[:action]}"
63
63
  }
64
+ metadata = ::LogStasher.metadata
65
+ result.merge!(:metadata => metadata) unless metadata&.empty?
66
+ result
64
67
  end
65
68
 
66
69
  # Monkey patching to enable exception logging
@@ -86,7 +89,6 @@ module LogStasher
86
89
  def extract_parameters(payload)
87
90
  if LogStasher.include_parameters?
88
91
  external_params = payload[:params].except(*INTERNAL_PARAMS)
89
-
90
92
  if LogStasher.serialize_parameters?
91
93
  { :params => JSON.generate(external_params) }
92
94
  else
@@ -8,6 +8,7 @@ module LogStasher
8
8
  config.logstasher.logger = nil
9
9
  config.logstasher.log_level = ::Logger::INFO
10
10
 
11
+ config.logstasher.metadata = {}
11
12
  config.before_initialize do
12
13
  options = config.logstasher
13
14
 
@@ -17,6 +18,7 @@ module LogStasher
17
18
  ::LogStasher.silence_standard_logging = options.silence_standard_logging
18
19
  ::LogStasher.logger = options.logger || default_logger
19
20
  ::LogStasher.logger.level = options.log_level
21
+ ::LogStasher.metadata = options.metadata
20
22
  end
21
23
 
22
24
  initializer 'logstasher.load' do
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "1.1.0"
2
+ VERSION = "1.4.1"
3
3
  end
data/lib/logstasher.rb CHANGED
@@ -8,6 +8,7 @@ module LogStasher
8
8
  attr_writer :include_parameters
9
9
  attr_writer :serialize_parameters
10
10
  attr_writer :silence_standard_logging
11
+ attr_accessor :metadata
11
12
 
12
13
  def append_fields(&block)
13
14
  @append_fields_callback = block
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ require 'logstasher/device/udp'
4
+
5
+ describe LogStasher::Device::UDP do
6
+
7
+ let(:default_options) {{
8
+ 'hostname' => '127.0.0.1',
9
+ 'port' => 31459
10
+ }}
11
+
12
+ it 'has default options' do
13
+ device = LogStasher::Device::UDP.new
14
+ expect(device.options).to eq(default_options)
15
+ end
16
+
17
+ it 'closes the udp socket on #close' do
18
+ device = LogStasher::Device::UDP.new
19
+ expect(device.socket).to receive(:close)
20
+ device.close
21
+ end
22
+
23
+ it 'works as a logger device' do
24
+ device = LogStasher::Device::UDP.new
25
+ expect(device).to receive(:write).with('foo')
26
+ logger = Logger.new(device)
27
+ logger << 'foo'
28
+ end
29
+
30
+ describe '#write' do
31
+ subject { LogStasher::Device::UDP.new }
32
+ it 'writes the log to the the socket' do
33
+ expect(subject.socket).to receive(:send).with('a log', 0, default_options['hostname'], default_options['port'])
34
+ subject.write('a log')
35
+ end
36
+ end
37
+ end
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
  require "logstasher/device"
4
4
  require "logstasher/device/redis"
5
5
  require "logstasher/device/syslog"
6
+ require "logstasher/device/udp"
6
7
 
7
8
  describe LogStasher::Device do
8
9
  describe ".factory" do
@@ -47,7 +48,21 @@ describe LogStasher::Device do
47
48
  device = ::LogStasher::Device.factory(:type => "syslog")
48
49
  expect(device).to be_a_kind_of(::LogStasher::Device::Syslog)
49
50
  end
51
+
52
+ it "can create udp devices" do
53
+ expect(
54
+ ::LogStasher::Device
55
+ ).to receive(:require).with("logstasher/device/udp")
50
56
 
57
+ device = ::LogStasher::Device.factory(:type => "udp")
58
+ expect(device).to be_a_kind_of(::LogStasher::Device::UDP)
59
+ end
60
+
61
+ it "can create stdout devices" do
62
+ device = ::LogStasher::Device.factory(:type => "stdout")
63
+ expect(device).to eq $stdout
64
+ end
65
+
51
66
  it "fails to create unknown devices" do
52
67
  expect {
53
68
  ::LogStasher::Device.factory(:type => "unknown")
@@ -10,6 +10,12 @@ class MockController
10
10
  end
11
11
 
12
12
  class MockRequest
13
+ attr_accessor :env
14
+
15
+ def initialize
16
+ @env = { 'action_dispatch.request_id' => 1 }
17
+ end
18
+
13
19
  def remote_ip
14
20
  '127.0.0.1'
15
21
  end
@@ -19,6 +25,7 @@ describe LogStasher::LogSubscriber do
19
25
  subject { described_class.new }
20
26
 
21
27
  let(:logger) { ::Logger.new('/dev/null') }
28
+
22
29
  let(:mock_controller) { MockController.new }
23
30
  let(:mock_request) { MockRequest.new }
24
31
  let(:context) {{ :controller => mock_controller, :request => mock_request }}
@@ -46,10 +53,12 @@ describe LogStasher::LogSubscriber do
46
53
  :path => '/users/1',
47
54
  :status => 200
48
55
  }}
56
+ let(:data) { { "namespace" => "test", "appversion" => "v1" } }
49
57
 
50
58
  let(:event) { double(:payload => payload, :duration => duration) }
51
59
 
52
60
  it 'logs the event in logstash format' do
61
+ ::LogStasher.metadata = data
53
62
  expect(logger).to receive(:<<) do |json|
54
63
  expect(JSON.parse(json)).to eq({
55
64
  '@timestamp' => timestamp,
@@ -64,7 +73,9 @@ describe LogStasher::LogSubscriber do
64
73
  'path' => payload[:path],
65
74
  'route' => "#{payload[:controller]}##{payload[:action]}",
66
75
  'status' => payload[:status],
67
- 'runtime' => { 'total' => duration }
76
+ 'runtime' => { 'total' => duration },
77
+ 'request_id' => 1,
78
+ 'metadata' => data
68
79
  })
69
80
  end
70
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md-logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Christensen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -85,6 +85,7 @@ files:
85
85
  - lib/logstasher/device.rb
86
86
  - lib/logstasher/device/redis.rb
87
87
  - lib/logstasher/device/syslog.rb
88
+ - lib/logstasher/device/udp.rb
88
89
  - lib/logstasher/log_subscriber.rb
89
90
  - lib/logstasher/railtie.rb
90
91
  - lib/logstasher/silent_logger.rb
@@ -96,6 +97,7 @@ files:
96
97
  - logstasher.gemspec
97
98
  - spec/lib/logstasher/device/redis_spec.rb
98
99
  - spec/lib/logstasher/device/syslog_spec.rb
100
+ - spec/lib/logstasher/device/udp_spec.rb
99
101
  - spec/lib/logstasher/device_spec.rb
100
102
  - spec/lib/logstasher/log_subscriber_spec.rb
101
103
  - spec/lib/logstasher/railtie_spec.rb
@@ -105,7 +107,7 @@ homepage: https://github.com/moneydesktop/logstasher
105
107
  licenses:
106
108
  - MIT
107
109
  metadata: {}
108
- post_install_message:
110
+ post_install_message:
109
111
  rdoc_options: []
110
112
  require_paths:
111
113
  - lib
@@ -120,14 +122,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.5.1
125
- signing_key:
125
+ rubygems_version: 3.2.28
126
+ signing_key:
126
127
  specification_version: 4
127
128
  summary: Awesome rails logs
128
129
  test_files:
129
130
  - spec/lib/logstasher/device/redis_spec.rb
130
131
  - spec/lib/logstasher/device/syslog_spec.rb
132
+ - spec/lib/logstasher/device/udp_spec.rb
131
133
  - spec/lib/logstasher/device_spec.rb
132
134
  - spec/lib/logstasher/log_subscriber_spec.rb
133
135
  - spec/lib/logstasher/railtie_spec.rb