RTALogger 2.1.2 → 2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -2
- data/lib/RTALogger/version.rb +1 -1
- data/lib/log_factory_filter.rb +1 -1
- data/lib/log_factory_log_formatter.rb +1 -1
- data/lib/log_filter_base.rb +19 -0
- data/lib/log_filter_context.rb +3 -1
- data/lib/log_filter_message.rb +3 -1
- data/lib/log_filter_topic.rb +3 -1
- data/lib/log_formatter_base.rb +46 -1
- data/lib/log_formatter_json.rb +16 -3
- data/lib/log_formatter_text.rb +1 -4
- data/lib/log_manager.rb +2 -0
- data/lib/log_repository.rb +1 -0
- data/lib/log_repository_file.rb +2 -0
- data/lib/log_repository_fluentd.rb +2 -0
- data/lib/log_topic.rb +21 -7
- data/lib/log_topic_wrapper.rb +160 -0
- data/lib/rta_logger_config.json +7 -4
- data/lib/sample.rb +9 -0
- data/lib/string.rb +33 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed82424b9451e92cb8424657eff8192e25e6bcff6aa66eed5e23867dcbe9386a
|
4
|
+
data.tar.gz: 309892ff41c57d310929b27287c0c024406de2bef493ecbd7e25ac04608be14a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af198b2b5df5603f541d20aed1e618c4ec61b69f674302c0c6a6433f920f2089e08c24198a414a8ed9ab79556c2f5f95c5610411349a3f0c09ed07e6b9198b3b
|
7
|
+
data.tar.gz: 5ed2d9c7676d9c6713d2706bc27366bb3bdb7c98ed3c04615fe8bf72e6940bb3f7a52d942169358bd43e86f24a3f44217024d738b2a5e68cc5cf568a9885a9f6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -104,7 +104,8 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
104
104
|
"formatter":
|
105
105
|
{
|
106
106
|
"type": "text",
|
107
|
-
"delimiter": "|"
|
107
|
+
"delimiter": "|",
|
108
|
+
"colorize": true
|
108
109
|
},
|
109
110
|
"filters":
|
110
111
|
[
|
@@ -216,7 +217,8 @@ the result will be:
|
|
216
217
|
"formatter":
|
217
218
|
{
|
218
219
|
"type": "text",
|
219
|
-
"delimiter": "|"
|
220
|
+
"delimiter": "|",
|
221
|
+
"colorize": true
|
220
222
|
},
|
221
223
|
"filters":
|
222
224
|
[
|
@@ -305,6 +307,8 @@ the result will be:
|
|
305
307
|
- "foramtter" is the text, json or any custome defined types as LogRecord formatter
|
306
308
|
- "type": ["text"/"json"] type of formatter
|
307
309
|
- "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
|
310
|
+
- "colorize": [true/false] default value of this attribute is false.
|
311
|
+
if you need to colorize your out put format on standard output set this attribute to true.
|
308
312
|
if formatter not defined then the json formatter will be used
|
309
313
|
2- file: Store log data in a file.
|
310
314
|
- "type": "console"
|
@@ -348,6 +352,7 @@ the result will be:
|
|
348
352
|
"enable": [true/false] this will enable or disable filtering opration of current filter.
|
349
353
|
"default_regex": "valid regual expression" to compare with corresponding attribute.
|
350
354
|
* It's possible to implement customize filter classes and integerate with RTALogger filter factory.
|
355
|
+
* In RTALogger version 2.2.0 colorize out put format is availabel.
|
351
356
|
- topics: This is an optional item. When you need to customize a specific topic severity level or
|
352
357
|
enable value, you can define the settings here.
|
353
358
|
- title: The topic title to customize. (mandatoy).
|
data/lib/RTALogger/version.rb
CHANGED
data/lib/log_factory_filter.rb
CHANGED
@@ -9,7 +9,7 @@ module RTALogger
|
|
9
9
|
begin
|
10
10
|
load lib_file
|
11
11
|
rescue
|
12
|
-
raise "unable to load
|
12
|
+
raise "unable to load filter class file: #{lib_file}"
|
13
13
|
end
|
14
14
|
|
15
15
|
filter_class_name = 'RTALogger::' + ('log_filter_' + type.to_s).split('_').map(&:capitalize).join
|
@@ -21,7 +21,7 @@ module RTALogger
|
|
21
21
|
return nil unless formatter_class
|
22
22
|
result = formatter_class.new
|
23
23
|
|
24
|
-
return result if config_json.empty?
|
24
|
+
return result if config_json.nil? || config_json.empty?
|
25
25
|
result.load_config(config_json) if result.present?
|
26
26
|
return result
|
27
27
|
end
|
data/lib/log_filter_base.rb
CHANGED
@@ -3,11 +3,14 @@ module RTALogger
|
|
3
3
|
def initialize
|
4
4
|
@title = self.class.to_s.split('::').last.underscore
|
5
5
|
@enable = true
|
6
|
+
@action = :accept
|
6
7
|
end
|
7
8
|
|
8
9
|
attr_accessor :title
|
9
10
|
attr_accessor :enable
|
10
11
|
attr_accessor :default_regex
|
12
|
+
# possible values: accept, ignore
|
13
|
+
attr_accessor :action
|
11
14
|
|
12
15
|
def match_conditions(log_record)
|
13
16
|
return true if !@enable
|
@@ -18,11 +21,13 @@ module RTALogger
|
|
18
21
|
@title = config_json['title'] if config_json['title'].present?
|
19
22
|
@enable = config_json['enable'].nil? ? true : config_json['enable'].present?
|
20
23
|
@default_regex = config_json['default_regex'] if config_json['default_regex'].present?
|
24
|
+
@action = valid_action(config_json['action']) if config_json['action'].present?
|
21
25
|
end
|
22
26
|
|
23
27
|
def apply_run_time_config(config_json)
|
24
28
|
@enable = config_json['enable'].nil? ? true : config_json['enable'].present?
|
25
29
|
@default_regex = config_json['default_regex'] if config_json['default_regex'].present?
|
30
|
+
@action = valid_action(config_json['action']) if config_json['action'].present?
|
26
31
|
end
|
27
32
|
|
28
33
|
def to_builder
|
@@ -31,9 +36,23 @@ module RTALogger
|
|
31
36
|
json.title @title
|
32
37
|
json.enable @enable
|
33
38
|
json.default_regex @default_regex
|
39
|
+
json.action @action.to_s
|
34
40
|
end
|
35
41
|
|
36
42
|
jb
|
37
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def valid_action(action_value)
|
48
|
+
case action_value.to_s.downcase
|
49
|
+
when 'accept'
|
50
|
+
:accept
|
51
|
+
when 'ignore'
|
52
|
+
:ignore
|
53
|
+
else
|
54
|
+
:accept
|
55
|
+
end
|
56
|
+
end
|
38
57
|
end
|
39
58
|
end
|
data/lib/log_filter_context.rb
CHANGED
@@ -7,7 +7,9 @@ module RTALogger
|
|
7
7
|
result = super
|
8
8
|
return result unless result
|
9
9
|
|
10
|
-
|
10
|
+
result = default_regex.present? ? (Regexp.new(@default_regex).match(log_record.context_id.to_s)) : result
|
11
|
+
result = !result if @action == :ignore
|
12
|
+
return result
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/log_filter_message.rb
CHANGED
@@ -7,7 +7,9 @@ module RTALogger
|
|
7
7
|
result = super
|
8
8
|
return result unless result
|
9
9
|
|
10
|
-
|
10
|
+
result = default_regex.present? ? (Regexp.new(@default_regex).match(log_record.full_message)) : result
|
11
|
+
result = !result if @action == :ignore
|
12
|
+
return result
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/log_filter_topic.rb
CHANGED
@@ -7,7 +7,9 @@ module RTALogger
|
|
7
7
|
result = super
|
8
8
|
return result unless result
|
9
9
|
|
10
|
-
|
10
|
+
result = default_regex.present? ? (Regexp.new(@default_regex).match(log_record.topic_title)) : result
|
11
|
+
result = !result if @action == :ignore
|
12
|
+
return result
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/log_formatter_base.rb
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
require 'jbuilder'
|
2
2
|
require_relative 'string'
|
3
|
+
require_relative 'severity_level'
|
3
4
|
|
4
5
|
module RTALogger
|
5
6
|
class LogFormatterBase
|
7
|
+
include SeverityLevel
|
8
|
+
|
6
9
|
def initialize
|
7
10
|
@delimiter = '|'
|
11
|
+
@colorize = false
|
8
12
|
end
|
9
13
|
|
10
14
|
attr_accessor :delimiter
|
15
|
+
attr_accessor :colorize
|
11
16
|
|
12
17
|
def load_config(config_json)
|
18
|
+
return unless config_json.present?
|
19
|
+
|
13
20
|
@delimiter = config_json['delimiter'].nil? ? true : config_json['delimiter']
|
21
|
+
@colorize = config_json['colorize'].nil? ? false : config_json['colorize']
|
14
22
|
end
|
15
23
|
|
16
24
|
def format(log_record)
|
@@ -20,7 +28,8 @@ module RTALogger
|
|
20
28
|
def to_builder
|
21
29
|
jb = Jbuilder.new do |json|
|
22
30
|
json.type self.class.to_s.split('::').last.underscore.sub('log_formatter_', '')
|
23
|
-
json.delimiter delimiter
|
31
|
+
json.delimiter @delimiter
|
32
|
+
json.colorize @colorize
|
24
33
|
end
|
25
34
|
|
26
35
|
jb
|
@@ -29,5 +38,41 @@ module RTALogger
|
|
29
38
|
def reveal_config
|
30
39
|
to_builder.target!
|
31
40
|
end
|
41
|
+
|
42
|
+
def apply_run_time_config(config_json)
|
43
|
+
return unless config_json.present?
|
44
|
+
|
45
|
+
@delimiter = config_json['delimiter'] unless config_json['delimiter'].nil?
|
46
|
+
@colorize = config_json['colorize'] unless config_json['colorize'].nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def severity_text(severity)
|
52
|
+
text = parse_severity_level_to_s(severity)
|
53
|
+
text = severity_colorized_text(severity, text) if @colorize
|
54
|
+
return text
|
55
|
+
end
|
56
|
+
|
57
|
+
def severity_colorized_text(severity, text)
|
58
|
+
case severity
|
59
|
+
when 0
|
60
|
+
text.trace_color
|
61
|
+
when 1
|
62
|
+
text.debug_color
|
63
|
+
when 2
|
64
|
+
text
|
65
|
+
when 3
|
66
|
+
text.warning_color
|
67
|
+
when 4
|
68
|
+
text.error_color
|
69
|
+
when 5
|
70
|
+
text.fatal_color
|
71
|
+
when 6
|
72
|
+
text.unknown_color
|
73
|
+
else
|
74
|
+
text
|
75
|
+
end
|
76
|
+
end
|
32
77
|
end
|
33
78
|
end
|
data/lib/log_formatter_json.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'jbuilder'
|
2
2
|
require_relative 'log_formatter_base'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'string'
|
4
4
|
|
5
5
|
module RTALogger
|
6
6
|
# json formatter which receive log_record and
|
7
7
|
# returns it's data as json string
|
8
8
|
class LogFormatterJson < LogFormatterBase
|
9
|
-
include SeverityLevel
|
10
9
|
|
11
10
|
def format(log_record)
|
12
11
|
return '' unless log_record
|
@@ -20,7 +19,21 @@ module RTALogger
|
|
20
19
|
json.message log_record.message.flatten.join(' ')
|
21
20
|
end
|
22
21
|
|
23
|
-
jb.target!
|
22
|
+
result = jb.target!
|
23
|
+
result = colorize_json(result) if @colorize
|
24
|
+
|
25
|
+
return result
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def colorize_json(json_text)
|
31
|
+
json_text.gsub(/"severity":"TRACE"/i, '"severity":"TRACE"'.trace_color)
|
32
|
+
.gsub(/"severity":"DEBUG"/i, '"severity":"DEBUG"'.debug_color)
|
33
|
+
.gsub(/"severity":"WARN"/i, '"severity":"WARN"'.warning_color)
|
34
|
+
.gsub(/"severity":"ERROR"/i, '"severity":"ERROR"'.error_color)
|
35
|
+
.gsub(/"severity":"FATAL"/i, '"severity":"FATAL"'.fatal_color)
|
36
|
+
.gsub(/"severity":"UNKNOWN"/i, '"severity":"UNKNOWN"'.unknown_color)
|
24
37
|
end
|
25
38
|
end
|
26
39
|
end
|
data/lib/log_formatter_text.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require_relative 'log_formatter_base'
|
2
|
-
require_relative 'severity_level'
|
3
2
|
|
4
3
|
module RTALogger
|
5
4
|
# text formatter which receive log_record and
|
6
5
|
# returns it's data as delimited text string
|
7
6
|
class LogFormatterText < LogFormatterBase
|
8
|
-
include SeverityLevel
|
9
|
-
|
10
7
|
def format(log_record)
|
11
8
|
return '' unless log_record
|
12
9
|
|
@@ -14,7 +11,7 @@ module RTALogger
|
|
14
11
|
result << @delimiter << log_record.app_name
|
15
12
|
result << @delimiter << log_record.topic_title
|
16
13
|
result << @delimiter << log_record.context_id.to_s
|
17
|
-
result << @delimiter <<
|
14
|
+
result << @delimiter << severity_text(log_record.severity)
|
18
15
|
result << @delimiter << log_record.message.join(' ').gsub(delimiter, '$<$')
|
19
16
|
|
20
17
|
result
|
data/lib/log_manager.rb
CHANGED
@@ -71,6 +71,7 @@ module RTALogger
|
|
71
71
|
config_json = load_config_from_json_file(file_name, title)
|
72
72
|
@config_file_name = file_name if config_json
|
73
73
|
apply_config(config_json)
|
74
|
+
self
|
74
75
|
rescue StandardError => e
|
75
76
|
@propagator.drop_all_repositories
|
76
77
|
@propagator.add_log_repository(LogFactory.create_repository(:console))
|
@@ -79,6 +80,7 @@ module RTALogger
|
|
79
80
|
def config_use_json_string(config_string, title = '')
|
80
81
|
config_json = load_config_from_json_string(config_string, title)
|
81
82
|
apply_config(config_json)
|
83
|
+
self
|
82
84
|
rescue StandardError => e
|
83
85
|
@propagator.drop_all_repositories
|
84
86
|
@propagator.add_log_repository(LogFactory.create_repository(:console))
|
data/lib/log_repository.rb
CHANGED
@@ -86,6 +86,7 @@ module RTALogger
|
|
86
86
|
def apply_run_time_config(config_json)
|
87
87
|
return unless config_json
|
88
88
|
@enable = config_json['enable'] unless config_json['enable'].nil?
|
89
|
+
@formatter.apply_run_time_config(config_json['formatter'])
|
89
90
|
apply_run_time_config_filters(config_json)
|
90
91
|
end
|
91
92
|
|
data/lib/log_repository_file.rb
CHANGED
@@ -62,6 +62,8 @@ module RTALogger
|
|
62
62
|
@port = config_json['port'] unless config_json['port'].nil?
|
63
63
|
@tls_options = config_json['tls_options'] unless config_json['tls_options'].nil?
|
64
64
|
@semaphore.synchronize { @fluent_logger = nil }
|
65
|
+
|
66
|
+
@formatter.colorize = false
|
65
67
|
end
|
66
68
|
|
67
69
|
protected
|
data/lib/log_topic.rb
CHANGED
@@ -22,33 +22,47 @@ module RTALogger
|
|
22
22
|
attr_accessor :severity_level
|
23
23
|
|
24
24
|
def trace(context_id, *message)
|
25
|
-
add(context_id, TRACE, message) if
|
25
|
+
add(context_id, TRACE, message) if trace?
|
26
26
|
end
|
27
27
|
|
28
28
|
def debug(context_id, *message)
|
29
|
-
add(context_id, DEBUG, message) if
|
29
|
+
add(context_id, DEBUG, message) if debug?
|
30
30
|
end
|
31
31
|
|
32
32
|
def info(context_id, *message)
|
33
|
-
add(context_id, INFO, message) if
|
33
|
+
add(context_id, INFO, message) if info?
|
34
34
|
end
|
35
35
|
|
36
36
|
def warning(context_id, *message)
|
37
|
-
add(context_id, WARN, message) if
|
37
|
+
add(context_id, WARN, message) if warn?
|
38
38
|
end
|
39
39
|
|
40
40
|
def error(context_id, *message)
|
41
|
-
add(context_id, ERROR, message) if
|
41
|
+
add(context_id, ERROR, message) if error?
|
42
42
|
end
|
43
43
|
|
44
44
|
def fatal(context_id, *message)
|
45
|
-
add(context_id, FATAL, message) if
|
45
|
+
add(context_id, FATAL, message) if fatal?
|
46
46
|
end
|
47
47
|
|
48
48
|
def unknown(context_id, *message)
|
49
|
-
add(context_id, UNKNOWN, message) if
|
49
|
+
add(context_id, UNKNOWN, message) if unknown?
|
50
50
|
end
|
51
51
|
|
52
|
+
def trace?; @severity_level.to_i <= TRACE.to_i; end
|
53
|
+
|
54
|
+
def debug?; @severity_level.to_i <= DEBUG.to_i; end
|
55
|
+
|
56
|
+
def info?; @severity_level.to_i <= INFO.to_i; end
|
57
|
+
|
58
|
+
def warn?; @severity_level.to_i <= WARN.to_i; end
|
59
|
+
|
60
|
+
def error?; @severity_level.to_i <= ERROR.to_i; end
|
61
|
+
|
62
|
+
def fatal?; @severity_level.to_i <= FATAL.to_i; end
|
63
|
+
|
64
|
+
def unknown?; @severity_level.to_i <= UNKNOWN.to_i; end
|
65
|
+
|
52
66
|
def to_builder
|
53
67
|
jb = Jbuilder.new do |json|
|
54
68
|
json.title title
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module RTALogger
|
2
|
+
class LogTopicWrapper
|
3
|
+
def initialize(context_id, topic, level = 0)
|
4
|
+
@context_id = context_id
|
5
|
+
@topic = topic
|
6
|
+
level = level - 1
|
7
|
+
level = 0 if level.negative?
|
8
|
+
level = 5 if level > 5
|
9
|
+
self.level = level
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :progname
|
13
|
+
attr_accessor :context_id
|
14
|
+
|
15
|
+
# Logging severity.
|
16
|
+
module Severity
|
17
|
+
# Low-level information, mostly for developers.
|
18
|
+
DEBUG = 0
|
19
|
+
# Generic (useful) information about system operation.
|
20
|
+
INFO = 1
|
21
|
+
# A warning.
|
22
|
+
WARN = 2
|
23
|
+
# A handleable error condition.
|
24
|
+
ERROR = 3
|
25
|
+
# An unhandleable error that results in a program crash.
|
26
|
+
FATAL = 4
|
27
|
+
# An unknown message that should always be logged.
|
28
|
+
UNKNOWN = 5
|
29
|
+
end
|
30
|
+
include Severity
|
31
|
+
|
32
|
+
# Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
|
33
|
+
attr_reader :level
|
34
|
+
|
35
|
+
# Set logging severity threshold.
|
36
|
+
#
|
37
|
+
# +severity+:: The Severity of the log message.
|
38
|
+
def level=(severity)
|
39
|
+
if severity.is_a?(Integer)
|
40
|
+
severity = 0 if severity.negative?
|
41
|
+
severity = 5 if severity > 5
|
42
|
+
@level = severity
|
43
|
+
else
|
44
|
+
case severity.to_s.downcase
|
45
|
+
when 'debug'
|
46
|
+
@level = DEBUG
|
47
|
+
when 'info'
|
48
|
+
@level = INFO
|
49
|
+
when 'warn'
|
50
|
+
@level = WARN
|
51
|
+
when 'error'
|
52
|
+
@level = ERROR
|
53
|
+
when 'fatal'
|
54
|
+
@level = FATAL
|
55
|
+
when 'unknown'
|
56
|
+
@level = UNKNOWN
|
57
|
+
else
|
58
|
+
raise ArgumentError, "invalid log level: #{severity}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns +true+ iff the current severity level allows for the printing of
|
64
|
+
# +DEBUG+ messages.
|
65
|
+
def debug?;
|
66
|
+
@level <= DEBUG;
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns +true+ iff the current severity level allows for the printing of
|
70
|
+
# +INFO+ messages.
|
71
|
+
def info?;
|
72
|
+
@level <= INFO;
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns +true+ iff the current severity level allows for the printing of
|
76
|
+
# +WARN+ messages.
|
77
|
+
def warn?;
|
78
|
+
@level <= WARN;
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns +true+ iff the current severity level allows for the printing of
|
82
|
+
# +ERROR+ messages.
|
83
|
+
def error?;
|
84
|
+
@level <= ERROR;
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns +true+ iff the current severity level allows for the printing of
|
88
|
+
# +FATAL+ messages.
|
89
|
+
def fatal?;
|
90
|
+
@level <= FATAL;
|
91
|
+
end
|
92
|
+
|
93
|
+
def add(severity, message = nil, progname = nil)
|
94
|
+
severity ||= UNKNOWN
|
95
|
+
|
96
|
+
if progname.nil?
|
97
|
+
progname = @progname
|
98
|
+
end
|
99
|
+
if message.nil?
|
100
|
+
if block_given?
|
101
|
+
message = yield
|
102
|
+
else
|
103
|
+
message = progname
|
104
|
+
progname = @progname
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
rta_logger_topic_log(severity, message)
|
109
|
+
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
alias log add
|
114
|
+
|
115
|
+
def debug(progname = nil, &block)
|
116
|
+
add(DEBUG, nil, progname, &block)
|
117
|
+
end
|
118
|
+
|
119
|
+
def info(progname = nil, &block)
|
120
|
+
add(INFO, nil, progname, &block)
|
121
|
+
end
|
122
|
+
|
123
|
+
def warn(progname = nil, &block)
|
124
|
+
add(WARN, nil, progname, &block)
|
125
|
+
end
|
126
|
+
|
127
|
+
def error(progname = nil, &block)
|
128
|
+
add(ERROR, nil, progname, &block)
|
129
|
+
end
|
130
|
+
|
131
|
+
def fatal(progname = nil, &block)
|
132
|
+
add(FATAL, nil, progname, &block)
|
133
|
+
end
|
134
|
+
|
135
|
+
def unknown(progname = nil, &block)
|
136
|
+
add(UNKNOWN, nil, progname, &block)
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def rta_logger_topic_log(severity, message)
|
142
|
+
return if @topic.nil?
|
143
|
+
|
144
|
+
case severity
|
145
|
+
when DEBUG
|
146
|
+
@topic.debug(@context_id, message)
|
147
|
+
when INFO
|
148
|
+
@topic.info(@context_id, message)
|
149
|
+
when WARN
|
150
|
+
@topic.warning(@context_id, message)
|
151
|
+
when ERROR
|
152
|
+
@topic.error(@context_id, message)
|
153
|
+
when FATAL
|
154
|
+
@topic.fatal(@context_id, message)
|
155
|
+
when UNKNOWN
|
156
|
+
@topic.unknown(@context_id, message)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/lib/rta_logger_config.json
CHANGED
@@ -20,18 +20,21 @@
|
|
20
20
|
"formatter":
|
21
21
|
{
|
22
22
|
"type": "text",
|
23
|
-
"delimiter": "|"
|
23
|
+
"delimiter": "|",
|
24
|
+
"colorize": true
|
24
25
|
},
|
25
26
|
"filters":
|
26
27
|
[
|
27
28
|
{
|
28
29
|
"type": "topic",
|
30
|
+
"action" : "ignore",
|
29
31
|
"title": "topic_filter_1",
|
30
|
-
"enable":
|
31
|
-
"default_regex" : "^test$"
|
32
|
+
"enable": false,
|
33
|
+
"default_regex" : "^test$",
|
32
34
|
},
|
33
35
|
{
|
34
36
|
"type": "message",
|
37
|
+
"action" : "accept",
|
35
38
|
"title": "message_filter_1",
|
36
39
|
"enable": false,
|
37
40
|
"default_regex" : "error"
|
@@ -52,9 +55,9 @@
|
|
52
55
|
}
|
53
56
|
},
|
54
57
|
{
|
55
|
-
"enable": false,
|
56
58
|
"title": "fluentd_repo_1",
|
57
59
|
"type": "fluentd",
|
60
|
+
"enable": false,
|
58
61
|
"host": "localhost",
|
59
62
|
"port": "8888",
|
60
63
|
"formatter":
|
data/lib/sample.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require_relative 'log_factory_manager'
|
2
2
|
require_relative 'log_factory_repository'
|
3
|
+
# require_relative 'string'
|
4
|
+
|
5
|
+
# puts 'trace'.gray
|
6
|
+
# puts 'debug'.green
|
7
|
+
# puts 'info'
|
8
|
+
# puts 'warning'.brown
|
9
|
+
# puts 'error'.red
|
10
|
+
# puts 'fatal'.bg_red
|
11
|
+
# puts 'unknown'.bg_cyan
|
3
12
|
|
4
13
|
controller_name = 'test_controller'
|
5
14
|
userID = 5
|
data/lib/string.rb
CHANGED
@@ -1,9 +1,40 @@
|
|
1
1
|
class String
|
2
2
|
def underscore
|
3
3
|
self.gsub(/::/, '/').
|
4
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
5
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
4
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
5
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
6
6
|
tr("-", "_").
|
7
7
|
downcase
|
8
8
|
end
|
9
|
+
|
10
|
+
def black; "\e[30m#{self}\e[0m" end
|
11
|
+
def red; "\e[31m#{self}\e[0m" end
|
12
|
+
def green; "\e[32m#{self}\e[0m" end
|
13
|
+
def brown; "\e[33m#{self}\e[0m" end
|
14
|
+
def blue; "\e[34m#{self}\e[0m" end
|
15
|
+
def magenta; "\e[35m#{self}\e[0m" end
|
16
|
+
def cyan; "\e[36m#{self}\e[0m" end
|
17
|
+
def gray; "\e[37m#{self}\e[0m" end
|
18
|
+
|
19
|
+
def bg_black; "\e[40m#{self}\e[0m" end
|
20
|
+
def bg_red; "\e[41m#{self}\e[0m" end
|
21
|
+
def bg_green; "\e[42m#{self}\e[0m" end
|
22
|
+
def bg_brown; "\e[43m#{self}\e[0m" end
|
23
|
+
def bg_blue; "\e[44m#{self}\e[0m" end
|
24
|
+
def bg_magenta; "\e[45m#{self}\e[0m" end
|
25
|
+
def bg_cyan; "\e[46m#{self}\e[0m" end
|
26
|
+
def bg_gray; "\e[47m#{self}\e[0m" end
|
27
|
+
|
28
|
+
def bold; "\e[1m#{self}\e[22m" end
|
29
|
+
def italic; "\e[3m#{self}\e[23m" end
|
30
|
+
def underline; "\e[4m#{self}\e[24m" end
|
31
|
+
def blink; "\e[5m#{self}\e[25m" end
|
32
|
+
def reverse_color; "\e[7m#{self}\e[27m" end
|
33
|
+
|
34
|
+
def trace_color; self.gray end
|
35
|
+
def debug_color; self.green end
|
36
|
+
def warning_color; self.brown end
|
37
|
+
def error_color; self.red end
|
38
|
+
def fatal_color; self.bg_red end
|
39
|
+
def unknown_color; self.bg_cyan end
|
9
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RTALogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Babak Bahreini, RTA Backend Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluent-logger
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/log_repository_fluentd.rb
|
92
92
|
- lib/log_repository_udp.rb
|
93
93
|
- lib/log_topic.rb
|
94
|
+
- lib/log_topic_wrapper.rb
|
94
95
|
- lib/rta_logger_config.json
|
95
96
|
- lib/sample.rb
|
96
97
|
- lib/severity_level.rb
|