log_sinks 0.1.0 → 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: 1c36d2668770385f86b0fe13843d91fae5f9f2164d53d9a42aaca1a6d0859242
4
- data.tar.gz: 1b52160fef8827b617b7fb00b728b97b3641c3e5c70ef47b61e8e10b86e154a5
3
+ metadata.gz: 4b2cfa948d6048c9c99682ba32a3c89bd59d7d33ccbda18353d4581e48a44c0e
4
+ data.tar.gz: c256d194a28d23478e87a5002208143f33d7f5324f579a4ac6c15e9b764076cb
5
5
  SHA512:
6
- metadata.gz: 3c51e5bb67d705cbd01795883e8e8b3fa3a397e7bd82690c306f70c52fe41eea78c16a0cfc829fcbaf4a3c814716dca9b32c3bd30138f0b2ec9fdc40b25617c9
7
- data.tar.gz: e3bbfb26c3100466d1d95232d2512467f319b32371dfe4b07e261a26e90721b1fd29753b88dc6b6dcc0374a4cfae14713e3b6b54e3c9749c03c16c7a604e1fd9
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.0'
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.0
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
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.1.0
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements: