kybus-logger 0.2.2 → 0.2.3

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: 39fcb6ac69876e64bdf175f357c8602b3b24ddff49c6d31cc4158409641ccf93
4
- data.tar.gz: 562466fb26205e9a85646b94554a8b04e82607a22767eceb180513c346c0e3f0
3
+ metadata.gz: 3701342a891450befe67513434dbd187c2300563939717971ccf9f5cd8db7477
4
+ data.tar.gz: db83a143f6ea69bbbe49c193b841bf6ec4654a4eab2466883f1d1a8fe0a20558
5
5
  SHA512:
6
- metadata.gz: 9c6f800d57771c31f8a931f5501886c599cef32b05cb450d46771a8b47cada9050ae548d44e4c664a3a449eb3c0980cd8ada24f336799f1432ff1f684d74bccf
7
- data.tar.gz: e7514e3f9d425a41cd633a86e41c4ae51f6ccd274c43b031decdac894d5deb07966a9022ac1789bf4e39cf78ec33d5c3199bf8af0e928ba6f2e6092b494066dd
6
+ metadata.gz: 1516fb68602f9f241f0a1d8513b0aacb76c7c185793fe8996e158c8f0b220cf84a7bc847496d5b68975c6b72b1eb0929a6a2c4f43eddda93618f2eceecab5426
7
+ data.tar.gz: 8f512efdcb640b18701f66d7e0fcb08f2d5b7038e64a20b29cf7d8f90b852554c986ed3030235daaff95e10c253f56a518b11bc18adf628e19daf23c44e5c79c
@@ -21,15 +21,18 @@ module Kybus
21
21
  new(config)
22
22
  end
23
23
 
24
+ def init_log_file
25
+ register('file', @original_config['stdout'] ? $stdout : @original_config['file'] || 'application.log')
26
+ register('rotate_days', @original_config['rotate_days'] || 7)
27
+ register('rotate_size', @original_config['rotate_size'] || (100 * (1024**2))) # 100Mb
28
+ end
29
+
24
30
  def initialize(config)
25
31
  @original_config = config
26
- register('file', config['stdout'] ? STDOUT : config['file'] || 'application.log')
27
- register('rotate_days', config['rotate_days'] || 7)
28
- register('rotate_size', config['rotate_size'] || 100 * 1024**2) # 100Mb
32
+ init_log_file
29
33
  register('date_format', config['date_format'] || '%Y-%m-%d %H:%M:%S')
30
34
  register('severity', config['severity'] || 'info')
31
- register('log_format', config['log_format'] ||
32
- "%time,%sev,%pid,%tid,%mod,%json\n")
35
+ register('log_format', config['log_format'] || "%time,%sev,%pid,%tid,%mod,%json\n")
33
36
  register('blacklist', config['blacklist'] || %w[pass password])
34
37
  register('logger', logger)
35
38
  end
@@ -13,21 +13,33 @@ module Kybus
13
13
  # - %json: Data object encoded as json
14
14
  # default format:
15
15
  # "%time,%sev,%pid,%tid,%module,%json"
16
- def format_builder(format_string)
17
- proc do |frmt, sev, time, mod, data|
18
- meta = {
16
+ class LogCreator
17
+ attr_reader :frmt
18
+
19
+ def initialize(frmt, sev, time, mod)
20
+ @frmt = frmt
21
+ @meta = {
19
22
  '%sev': sev,
20
23
  '%time': time,
21
24
  '%mod': mod,
22
25
  '%pid': Process.pid.to_s(16),
23
26
  '%tid': Thread.current.object_id.to_s(16)
24
27
  }
28
+ end
29
+
30
+ def log_data(data)
25
31
  entry = frmt.dup
26
- meta.each { |k, v| entry.gsub!(k.to_s, v.to_s) }
32
+ @meta.each { |k, v| entry.gsub!(k.to_s, v.to_s) }
27
33
  # json is slower than the meta records, so it is better to replace
28
34
  # in a lazy way.
29
- # TODO: Move lazy tags to a pluggin-based model.
35
+ # TODO: Move lazy tags to a plugin-based model.
30
36
  entry.gsub('%json', data.to_json) if frmt.include?('%json')
37
+ end
38
+ end
39
+
40
+ def format_builder(format_string)
41
+ proc do |frmt, sev, time, mod, data|
42
+ LogCreator.new(frmt, sev, time, mod).log_data(data)
31
43
  end.curry.call(format_string)
32
44
  end
33
45
  end
@@ -13,37 +13,34 @@ module Kybus
13
13
  LogMethods.register(:global_config, config)
14
14
  end
15
15
 
16
- def log_info(msg, data = {})
17
- log_raw(:info, msg, data, data[:debug])
18
- end
19
-
20
- def log_warn(msg, data = {})
21
- log_raw(:warn, msg, data, data[:debug])
22
- end
23
-
24
- def log_error(msg, data = {})
25
- log_raw(:error, msg, data, data[:debug])
26
- end
27
-
28
- def log_fatal(msg, data = {})
29
- log_raw(:fatal, msg, data, data[:debug])
30
- end
31
-
32
- def log_debug(msg, data = {})
33
- log_raw(:debug, msg, data, data[:debug])
16
+ %i[debug info warn error fatal].each do |level|
17
+ define_method("log_#{level}".to_s) do |msg, data = nil|
18
+ debug = {}
19
+ case data
20
+ when Hash
21
+ debug = data.delete(:debug)
22
+ when NilClass
23
+ data = {}
24
+ when String
25
+ data = [data]
26
+ when Exception
27
+ data = { message: data.message, class: data.class, stack: data.backtrace }
28
+ end
29
+ log_raw(level, msg, data, debug)
30
+ end
34
31
  end
35
32
 
36
33
  def log_metric(metric:, amount:, group: nil, time: nil)
37
- log_info('Metric', metric: metric, value: amount,
38
- group: group, time: time)
34
+ log_info('Metric', metric:, value: amount,
35
+ group:, time:)
39
36
  end
40
37
 
41
38
  def log_alert(description:, group:, alert_severity:, notify_group:)
42
39
  log_fatal('Alert Triggered',
43
- description: description,
44
- group: group,
40
+ description:,
41
+ group:,
45
42
  severity: alert_severity,
46
- notify_group: notify_group)
43
+ notify_group:)
47
44
  end
48
45
 
49
46
  def log_raw(severity, msg, data, debug = {})
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kybus
4
4
  module Logger
5
- VERSION = '0.2.2'
5
+ VERSION = '0.2.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kybus-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilberto Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2022-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kybus-core
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '12.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '12.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rdoc
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,8 @@ files:
124
124
  homepage: https://github.com/tachomex/kybus
125
125
  licenses:
126
126
  - MIT
127
- metadata: {}
127
+ metadata:
128
+ rubygems_mfa_required: 'true'
128
129
  post_install_message:
129
130
  rdoc_options: []
130
131
  require_paths:
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  - !ruby/object:Gem::Version
141
142
  version: '0'
142
143
  requirements: []
143
- rubygems_version: 3.1.4
144
+ rubygems_version: 3.3.7
144
145
  signing_key:
145
146
  specification_version: 4
146
147
  summary: Implements a kybus-logger with a format based on cute_logger