kybus-logger 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kybus/logger/config.rb +23 -11
- data/lib/kybus/logger/format.rb +17 -5
- data/lib/kybus/logger/log_methods.rb +20 -23
- data/lib/kybus/logger/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e8425c5c0e962f2a2e4a9d60d8e36c545d16c94c93f4c7a35059f13f6644b1a
|
4
|
+
data.tar.gz: 5a9cd41cb837ae50d22d08bb409cb77844ab8a105503b5203c96c1f56e1dce35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c80780a263df96fe7edb480a25bcf1ea78c16b9f00087184a0483c00c2125d73be8f3d69ebfa06577718a3d2472e7ba48be32deca856066c3fd009e11a64e5ed
|
7
|
+
data.tar.gz: ec534f16743c6cdfeae02261d2e99a4b8f68e0edf8568e85401115dee54e7a4135b624f908dc91613ab58a8c909ac028cee52388905c17ec7ad0ce38c6d1d251
|
data/lib/kybus/logger/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'logger'
|
4
|
-
|
5
4
|
require_relative 'format'
|
6
5
|
|
7
6
|
module Kybus
|
@@ -21,26 +20,39 @@ module Kybus
|
|
21
20
|
new(config)
|
22
21
|
end
|
23
22
|
|
23
|
+
def init_log_file
|
24
|
+
log_output = if @original_config['stdout'].nil? || @original_config['stdout']
|
25
|
+
$stdout
|
26
|
+
else
|
27
|
+
@original_config['file'] || 'application.log'
|
28
|
+
end
|
29
|
+
register('file', log_output)
|
30
|
+
register('rotate_days', @original_config['rotate_days'] || 7)
|
31
|
+
register('rotate_size', @original_config['rotate_size'] || (100 * (1024**2))) # 100Mb
|
32
|
+
end
|
33
|
+
|
24
34
|
def initialize(config)
|
25
35
|
@original_config = config
|
26
|
-
|
27
|
-
register('rotate_days', config['rotate_days'] || 7)
|
28
|
-
register('rotate_size', config['rotate_size'] || 100 * 1024**2) # 100Mb
|
36
|
+
init_log_file
|
29
37
|
register('date_format', config['date_format'] || '%Y-%m-%d %H:%M:%S')
|
30
38
|
register('severity', config['severity'] || 'info')
|
31
|
-
register('log_format', config['log_format'] ||
|
32
|
-
"%time,%sev,%pid,%tid,%mod,%json\n")
|
39
|
+
register('log_format', config['log_format'] || "%time,%sev,%pid,%tid,%mod,%json\n")
|
33
40
|
register('blacklist', config['blacklist'] || %w[pass password])
|
34
41
|
register('logger', logger)
|
35
42
|
end
|
36
43
|
|
37
44
|
def logger
|
38
45
|
@logger ||= begin
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
log_output = resource('file')
|
47
|
+
logger = if log_output == $stdout
|
48
|
+
::Logger.new(log_output)
|
49
|
+
else
|
50
|
+
::Logger.new(
|
51
|
+
log_output,
|
52
|
+
resource('rotate_days'),
|
53
|
+
resource('rotate_size')
|
54
|
+
)
|
55
|
+
end
|
44
56
|
$stdout.sync = true if @original_config['stdout']
|
45
57
|
logger.sev_threshold = SEVERITIES[resource('severity')]
|
46
58
|
logger.datetime_format = resource('date_format')
|
data/lib/kybus/logger/format.rb
CHANGED
@@ -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
|
-
|
17
|
-
|
18
|
-
|
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
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
38
|
-
group
|
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
|
44
|
-
group
|
40
|
+
description:,
|
41
|
+
group:,
|
45
42
|
severity: alert_severity,
|
46
|
-
notify_group:
|
43
|
+
notify_group:)
|
47
44
|
end
|
48
45
|
|
49
46
|
def log_raw(severity, msg, data, debug = {})
|
data/lib/kybus/logger/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilberto Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-03 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: '
|
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: '
|
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.
|
144
|
+
rubygems_version: 3.5.14
|
144
145
|
signing_key:
|
145
146
|
specification_version: 4
|
146
147
|
summary: Implements a kybus-logger with a format based on cute_logger
|