md-logstasher 1.6.0 → 1.7.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: 628b152041e0a0d8218761c1ab723f43b16ff6a9746fcf102e5b0a8d03aea76e
4
- data.tar.gz: a3283254f14aef786d70dda74cae35d081d607e67a37522fff292ddab6119e80
3
+ metadata.gz: 69eb9914c59b6fdde645a4c54c51785fbe677f287c18e462f4283dac2af7ef70
4
+ data.tar.gz: c5a6066a51d68cbfa123c8bd1e30138ee90efac02a8a19cf7ed1da56e68d09f7
5
5
  SHA512:
6
- metadata.gz: 68806d2f4d08aa90a7c61487d2101e9cbfa2802d1021986dc39d1d9469196d8524d6e07cdcb63b3df104c0198beff6b9510f3f2d876ddc79b4c565b5f2d2fe1e
7
- data.tar.gz: 38f876594090f8a545dcfcd5380142bbfb1d9b34c726b2d0cb6de96d547ee41aaf5463c245279adbe50d694f9ab6be0a30fd6cdc45ffd0ccf5efd1e66322065f
6
+ metadata.gz: 89642d029ce8980eeb786953c580ab5574122a3bec77c096611c9a0c380b6230924375bf972b48f36af28134ac1474945a6c53983368eb0184d3246cb18b2ca2
7
+ data.tar.gz: b38aced68aa13148b72539aac1aeca810bd10b34558e776c06a0400195675ab387b86c19b463b572a59c6704cb24280db7c38c06dfa3ffc17d295e2bed075387
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
data/lib/logstasher.rb CHANGED
@@ -46,18 +46,20 @@ module LogStasher
46
46
 
47
47
  def log_as_json(payload, as_logstash_event: false)
48
48
  payload = payload.dup
49
- payload.merge!(:metadata => metadata) if !metadata&.empty? && payload.is_a?(::Hash)
49
+
50
+ # Merge in metadata if configured. This supports a Hash and a fully formed
51
+ # LogStash::Event.
52
+ if !metadata.empty?
53
+ payload.merge!(:metadata => metadata) if payload.is_a?(::Hash)
54
+ payload.append(:metadata => metadata) if payload.is_a?(::LogStash::Event)
55
+ end
50
56
 
51
57
  # Wrap the hash in a logstash event if the caller wishes for a specific
52
58
  # formatting applied to the hash. This is used by log subscriber, for
53
59
  # example.
54
- json_payload = if as_logstash_event
55
- ::LogStash::Event.new(payload).to_json
56
- else
57
- payload.to_json
58
- end
60
+ payload = ::LogStash::Event.new(payload) if as_logstash_event
59
61
 
60
- logger << json_payload + $INPUT_RECORD_SEPARATOR
62
+ logger << payload.to_json + $INPUT_RECORD_SEPARATOR
61
63
  end
62
64
 
63
65
  def logger
@@ -36,6 +36,14 @@ describe ::LogStasher do
36
36
  ::LogStasher.log_as_json(:yolo => :brolo)
37
37
  end
38
38
 
39
+ it "merges metadata for LogStash::Event types" do
40
+ expect(::LogStasher.logger).to receive(:<<) do |json|
41
+ expect(::JSON.parse(json)).to match(a_hash_including("yolo" => "brolo", "metadata" => { "namespace" => "cooldude" }))
42
+ end
43
+
44
+ ::LogStasher.log_as_json(::LogStash::Event.new(:yolo => :brolo))
45
+ end
46
+
39
47
  it "does not merge metadata on an array" do
40
48
  expect(::LogStasher.logger).to receive(:<<) do |json|
41
49
  expect(::JSON.parse(json)).to eq([{ "yolo" => "brolo" }])
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.6.0
4
+ version: 1.7.0
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: 2022-09-09 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -108,7 +108,7 @@ homepage: https://github.com/moneydesktop/logstasher
108
108
  licenses:
109
109
  - MIT
110
110
  metadata: {}
111
- post_install_message:
111
+ post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
114
114
  - lib
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.2.28
127
- signing_key:
126
+ rubygems_version: 3.1.6
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: Awesome rails logs
130
130
  test_files: