loggun 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64690d6ecfdadf2c32a49d2a688de83dfd2ea90a22e8c87e24544fd6c025100a
4
- data.tar.gz: 428175cd75ee0bef72c3c74450df4c69069a37997794a253a86147883e7d14db
3
+ metadata.gz: 3a78f3c782857269e283aa2f00ef6f5a2002e57c1e0d2fe5d43284a54d5aa106
4
+ data.tar.gz: fb9d8dad64af86d1f43c510dc34c1fd3acb9a515441315973ab0a5b72d493099
5
5
  SHA512:
6
- metadata.gz: e680f49877dcb8418b3653c38ec42187ba17050ba58ac061d383ca9e3cf836d6739f7ae111ec9a7352b8d9ea721a1b4e09ad4d91bb022c6d61b2ff6bacdd4d5f
7
- data.tar.gz: 0e5e5cedcdd59e80c71979a4ae90f87a59b76565b4e02754a2b3c35d1bd264ce8e619330b4944e6035e524ff26e56ba65be0c30b3f71114b7f29d2f84be629cb
6
+ metadata.gz: e0d93bbbe8ed26b5c5decc4d88c16876d4db185d5ae415b07fb47a23848149183e56fb0be6128f8c321410d205d19778228888f9cdb7ce57414ba29c380f22db
7
+ data.tar.gz: '08d78b02426b5b3da9a31b90bf3715c9728de0eaeb40ed9d5b55ccfeab76c3e241146fcdaa9f052b11ee233a40fdb07e68be5f33ff4a104467cbd08b959fe07a'
data/README.md CHANGED
@@ -49,6 +49,7 @@ Loggun::Config.configure do |config|
49
49
  config.precision = :milliseconds
50
50
  config.pattern = '%{time} - %{pid} %{severity} %{type} %{tags_text} %{message}'
51
51
  config.parent_transaction_to_message = false
52
+ config.message_format = :json
52
53
 
53
54
  config.modifiers.rails = true
54
55
  config.modifiers.sidekiq = false
@@ -64,6 +65,9 @@ end
64
65
  Доступные ключи: `time`, `pid`, `severity`, `type`, `tags_text`, `message`, `parent_transaction`
65
66
  - `parent_transaction_to_message` - признак необходимости добавлять значение `parent_transaction` в тело логируемого сообщения.
66
67
  Вне зависимости от данной настройки можно использовать ключ `parent_transaction` в шаблоне `pattern`.
68
+ - `message_format` - формат переменной message в шаблоне pattern. Доступны два формата:
69
+ - `:json` - `message` логгируется как json строка
70
+ - `:key_value` - `message` логгируется в формате `key1=value1 key2=value2`
67
71
  - `modifiers` - модификаторы для переопределения формата логирования указанного компонента. См. далее.
68
72
 
69
73
  #### Модификаторы
@@ -8,6 +8,7 @@ module Loggun
8
8
  DEFAULTS = {
9
9
  pattern: '%{time} - %{pid} %{severity} %{type} %{tags_text} %{message}',
10
10
  parent_transaction_to_message: true,
11
+ message_format: :json,
11
12
  precision: :milliseconds,
12
13
  incoming_http: {
13
14
  controllers: %w[ApplicationController],
@@ -20,11 +21,13 @@ module Loggun
20
21
  }
21
22
  }.freeze
22
23
  DEFAULT_MODIFIERS = %i[rails active_record sidekiq clockwork outgoing_http].freeze
24
+ MESSAGE_FORMATS = %i[json key_value].freeze
23
25
 
24
26
  attr_accessor(
25
27
  :formatter,
26
28
  :pattern,
27
29
  :parent_transaction_to_message,
30
+ :message_format,
28
31
  :precision,
29
32
  :modifiers,
30
33
  :custom_modifiers
@@ -35,6 +38,7 @@ module Loggun
35
38
  @precision = DEFAULTS[:precision]
36
39
  @pattern = DEFAULTS[:pattern]
37
40
  @parent_transaction_to_message = DEFAULTS[:parent_transaction_to_message]
41
+ @message_format = DEFAULTS[:message_format]
38
42
  @modifiers = Loggun::OrderedOptions.new
39
43
  @custom_modifiers = []
40
44
  set_default_modifiers
@@ -44,6 +48,7 @@ module Loggun
44
48
  def configure(&block)
45
49
  block.call(instance)
46
50
  use_modifiers
51
+ check_config
47
52
  instance
48
53
  end
49
54
 
@@ -59,6 +64,12 @@ module Loggun
59
64
  instance.custom_modifiers.each(&:use)
60
65
  end
61
66
 
67
+ def check_config
68
+ return if MESSAGE_FORMATS.include? instance.message_format
69
+
70
+ raise FailureConfiguration, 'Unknown value for message_format'
71
+ end
72
+
62
73
  def setup_formatter(app, formatter = nil)
63
74
  Loggun.logger = app.logger
64
75
  Loggun.logger.formatter = formatter || instance.formatter
@@ -91,5 +102,7 @@ module Loggun
91
102
  3 # milliseconds
92
103
  end
93
104
  end
105
+
106
+ class FailureConfiguration < StandardError; end
94
107
  end
95
108
  end
@@ -14,7 +14,7 @@ module Loggun
14
14
  if config.parent_transaction_to_message && parent_transaction
15
15
  message[:parent_transaction] = parent_transaction
16
16
  end
17
- message = JSON.generate(message)
17
+ message = format_message(message)
18
18
  end
19
19
 
20
20
  data[:message] = message.to_s.tr("\r\n", ' ').strip
@@ -78,5 +78,16 @@ module Loggun
78
78
  def config
79
79
  Loggun::Config.instance
80
80
  end
81
+
82
+ def format_message(message)
83
+ if config.message_format == :json
84
+ JSON.generate(message)
85
+ elsif config.message_format == :key_value
86
+ message.map { |key, value| "#{key}=#{value}" }.join(' ')
87
+ else
88
+ warn('Unknown value for message_format')
89
+ JSON.generate(message)
90
+ end
91
+ end
81
92
  end
82
93
  end
@@ -1,3 +1,3 @@
1
1
  module Loggun
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Noskov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-04-21 00:00:00.000000000 Z
12
+ date: 2020-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler