log_sinks 0.1.1 → 0.2.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: ac8df2d8b7528852b0fd29c8c37c823373cc83274fec539b8fcf012484b2e790
4
- data.tar.gz: 13322ed9b4114cd56e26120796728119c0b1ac2314f78153d7da8eeaea68d7b4
3
+ metadata.gz: 4b2cfa948d6048c9c99682ba32a3c89bd59d7d33ccbda18353d4581e48a44c0e
4
+ data.tar.gz: c256d194a28d23478e87a5002208143f33d7f5324f579a4ac6c15e9b764076cb
5
5
  SHA512:
6
- metadata.gz: 3e0e066633d9eb2aae756344e4e654d1a7584ff75204f3a87f2eaa90cf5db710961b9f2aacf109364d58f5455fcf8a8b88e52ae7c00684f99321b933f25f3d42
7
- data.tar.gz: 9ca24c68e5be08cd536196927321aeb91f8ececa26b53007acd1fdfc3b0405794bdbb4d22a2b7059cbf7f6ef71d943b958f35ec8e503a38bac7bdf05c4119ab2
6
+ metadata.gz: 67abc22d62f8c8e381376bf1eca20c3e276b60284678e11ff39853bd51ebb43001512e55dd57013648a97bfdefa4f863c007484aab2127f134c6053e83fbed79
7
+ data.tar.gz: 8f2a78e041a9dd074a65269ead3c9b1481fa07ca357ecb8d6d030536089398bf714d993aad8dda6ff91bd9a160cd602363ea3f50f01bac537866335ad152b6fd
@@ -3,28 +3,14 @@
3
3
  module LogSinks
4
4
  # Represents a log event.
5
5
  class LogEvent
6
- def initialize(timestamp, level, logger_name, msg, meta: nil)
7
- @data = meta || {}
8
- @data[:timestamp] = timestamp
9
- @data[:level] = level
10
- @data[:logger_name] = logger_name
11
- @data[:message] = msg
12
- end
6
+ attr_reader :timestamp, :level, :logger_name, :message, :data
13
7
 
14
- def timestamp
15
- self[:timestamp]
16
- end
17
-
18
- def level
19
- self[:level]
20
- end
21
-
22
- def logger_name
23
- self[:logger_name]
24
- end
25
-
26
- def message
27
- self[:message]
8
+ def initialize(timestamp, level, logger_name, msg, meta: nil)
9
+ @data = (meta || {}).freeze
10
+ @timestamp = timestamp
11
+ @level = level
12
+ @logger_name = logger_name
13
+ @message = msg
28
14
  end
29
15
 
30
16
  def [](key)
@@ -57,7 +57,7 @@ module LogSinks
57
57
  msg = yield if msg.nil? && block_given?
58
58
  meta ||= {}
59
59
  meta[:error] = error unless error.nil?
60
- meta.merge!(MDC.items)
60
+ meta.merge!(MDC.items) if MDC.any?
61
61
  event = ::LogSinks::LogEvent.new(Time.now, level, @name, msg, meta: meta)
62
62
  dispatch_event event
63
63
  end
data/lib/log_sinks/mdc.rb CHANGED
@@ -19,6 +19,10 @@ module LogSinks
19
19
  MDC[key] = value
20
20
  end
21
21
 
22
+ def any?
23
+ context.any?
24
+ end
25
+
22
26
  def items
23
27
  context.dup.freeze
24
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogSinks
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_sinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Maraev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-02 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby