loggun 0.5.0 → 0.5.1

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: 2596dacc5a1bea907afccdabec538190ba574a623c19221189798a1a9f320c74
4
- data.tar.gz: 2ac4b17d0113f10c3742bf929165c5a6bf95c7273a9e8a2027fe48c170dfef3c
3
+ metadata.gz: 51f8b307222f4c0cd6a68a2e1190c505dfb85c98916e8bef75f8353308d6066e
4
+ data.tar.gz: a967d678e0ca4e52f7dc2f4387d2d04fe7097f10eb0cbfaccfe9c41d6c2de809
5
5
  SHA512:
6
- metadata.gz: a279ad6a07b077bf7af95aaeba39cae3085808e3e9ab77798a950d192d8e8c9f406b7f49c97f46d80bd7b8b12c5fe77bc38c0fff47c2ee0b055363862d8a45eb
7
- data.tar.gz: 410fc2d3b572a729f5e7c0ecde19426384b401dd8f2d87b89b20731c4dbcba20b89231b463e3e49c76220bdfafd7d058e75dfa3af88faec1b6645001485bb330
6
+ metadata.gz: 29b945bd8b60102ba564177193321458adc9226d6c5eb541be5e8ba06a591d9cef305d2a3c45180c011580b31acb78c6687b87941951268e35525bc5af110311
7
+ data.tar.gz: 18894d7473ac6a2700b96e61a1d3f2d5c4ff152546f464d1663b2aa891a6fb559856a99a1fe0b2205cdb83457818091f391ac2e137e9e6027cc72eb6b59b0bc5
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1 - 2020-09-22
4
+ * fix
5
+ * `message` string only in `log_format == :json`
6
+
3
7
  ## 0.5.0 - 2020-09-22
4
8
  * features
5
9
  * `config.log_format` - for control full log rows format
data/README.md CHANGED
@@ -108,11 +108,25 @@ end
108
108
 
109
109
  Доступные значения:
110
110
 
111
- - `:json` — лог формируется как JSON-строка игнорируя шаблон `pattern`;
111
+ - `:json` — лог формируется как JSON-строка игнорируя шаблон `pattern` и настройку `message_format`;
112
112
  - `:plain` — лог формируется по шаблону `pattern`.
113
113
 
114
114
  По умолчанию `:plain`.
115
115
 
116
+ При `log_format == :json` в `message` будет попадать только сообщение, которое было передано строкой. Сообщение,
117
+ переданное хешем попадет в поле `metadata`. Пример:
118
+ ```ruby
119
+ Loggun.info("my.best.action", "message string", test: true)
120
+ # {
121
+ # "metadata":{"test":true},
122
+ # "message":"message string",
123
+ # "type":"my.best.action",
124
+ # "timestamp":"2020-09-22T14:57:22.233+03:00",
125
+ # "severity":"INFO",
126
+ # ...
127
+ # }
128
+ ```
129
+
116
130
  - `exclude_keys` — список ключей, которые будут исключены из лога.
117
131
 
118
132
  Используется, если `log_format` имеет значение `:json` и список `only_keys` пуст.
@@ -8,30 +8,21 @@ module Loggun
8
8
  def call(severity, time, _program_name, message, loggun_type: nil)
9
9
  data = Hash.new(DEFAULT_VALUE)
10
10
  time = time.utc if config.force_utc
11
- message = prepare_message(message)
11
+
12
+ process_message(data, message)
13
+
14
+ data[:type] = loggun_type || Loggun.type || DEFAULT_VALUE.dup
12
15
 
13
16
  data[:timestamp] = time.iso8601(config.timestamp_precision)
14
17
  data[:time] = data[:timestamp] if config.log_format == :plain
15
- data[:pid] = Process.pid
16
- data[:message] = message
18
+
17
19
  data[:severity] = severity&.to_s || 'INFO'
20
+ data[:pid] = Process.pid
18
21
  data[:tags_text] = tags_text
19
- data[:type] = loggun_type || Loggun.type || DEFAULT_VALUE.dup
20
22
  data[:transaction_id] = Loggun.transaction_id
21
23
  data[:parent_transaction] = parent_transaction if parent_transaction
22
24
 
23
- if data[:transaction_id] && data[:type] != DEFAULT_VALUE &&
24
- data[:transaction_id].to_i != Process.pid
25
- data[:type] = "#{data[:type]}##{data[:transaction_id]}"
26
- end
27
-
28
- if config.log_format == :json
29
- data.except!(*config.exclude_keys) if config.only_keys.empty?
30
- data.slice!(*config.only_keys) if config.only_keys.any?
31
- JSON.generate(data) + "\n"
32
- else
33
- format(config.pattern + "\n", data)
34
- end
25
+ prepare_to_output(data)
35
26
  end
36
27
 
37
28
  def tagged(*tags)
@@ -71,18 +62,38 @@ module Loggun
71
62
 
72
63
  private
73
64
 
74
- def prepare_message(message)
65
+ def process_message(data, message)
75
66
  if message.is_a?(Hash)
76
67
  if config.parent_transaction_to_message && parent_transaction
77
68
  message[:parent_transaction] = parent_transaction
78
69
  end
79
- message = format_message(message) if config.log_format == :plain
70
+
71
+ if config.log_format == :plain
72
+ message = format_message(message)
73
+ else
74
+ simple_message = message.delete(:message)
75
+ data[:metadata] = message if message != {}
76
+ message = simple_message
77
+ end
80
78
  end
81
79
 
82
- if config.log_format == :plain
83
- message.to_s.tr("\r\n", ' ').strip
80
+ message = message.to_s.tr("\r\n", ' ').strip if config.log_format == :plain
81
+
82
+ data[:message] = message
83
+ end
84
+
85
+ def prepare_to_output(data)
86
+ if data[:transaction_id] && data[:type] != DEFAULT_VALUE &&
87
+ data[:transaction_id].to_i != Process.pid
88
+ data[:type] = "#{data[:type]}##{data[:transaction_id]}"
89
+ end
90
+
91
+ if config.log_format == :json
92
+ data.except!(*config.exclude_keys) if config.only_keys.empty?
93
+ data.slice!(*config.only_keys) if config.only_keys.any?
94
+ JSON.generate(data) + "\n"
84
95
  else
85
- message
96
+ format(config.pattern + "\n", data)
86
97
  end
87
98
  end
88
99
 
@@ -1,3 +1,3 @@
1
1
  module Loggun
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Noskov