RTALogger 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +165 -71
- data/lib/RTALogger/version.rb +1 -1
- data/lib/log_factory_log_formatter.rb +24 -9
- data/lib/log_factory_repository.rb +23 -42
- data/lib/log_factory_topic.rb +2 -2
- data/lib/log_formatter.rb +11 -1
- data/lib/log_formatter_json.rb +1 -1
- data/lib/log_formatter_text.rb +6 -6
- data/lib/log_manager.rb +99 -38
- data/lib/log_propagator.rb +2 -2
- data/lib/log_record.rb +1 -1
- data/lib/log_repository.rb +25 -1
- data/lib/log_repository_console.rb +6 -0
- data/lib/log_repository_file.rb +21 -2
- data/lib/log_repository_fluent.rb +23 -6
- data/lib/log_repository_udp.rb +14 -6
- data/lib/log_topic.rb +24 -14
- data/lib/rta_logger_config.json +43 -22
- data/lib/sample.rb +13 -2
- data/lib/severity_level.rb +60 -0
- metadata +3 -4
- data/lib/log_factory_file_logger.rb +0 -17
- data/lib/log_severity.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4c558e31bfbc739d0ad9ebb218c96c61fdcc354b6ae9a9c0daa3ea4743786c3
|
4
|
+
data.tar.gz: b00ec909d9a8791671e29e949fb19cfb31e59d7fbf353532a70bfb216e6b4e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6296831235e737111217cf51f4e3d477620d588319fb0540760b948028b26f87361e03cc7c453dd00ab3c4553a26ad045791e2d9e64d1153017246e664348bd
|
7
|
+
data.tar.gz: 39885f5f4f039199748d9201f632ac4e745bd41cced49971ddc70b9599281c556a2d85e3fb13332a76cb0b01d78f1efb88d510331071332ccfdcbd26528543a7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -81,6 +81,51 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
81
81
|
# the parameter is the json config file
|
82
82
|
log_manager.config_use_json_file('rta_logger_config.json')
|
83
83
|
```
|
84
|
+
- Sample configuration json file
|
85
|
+
```
|
86
|
+
{
|
87
|
+
"rta_logger":
|
88
|
+
{
|
89
|
+
"default_manager": "develop",
|
90
|
+
"log_managers":
|
91
|
+
[
|
92
|
+
{
|
93
|
+
"manager_name": "develop",
|
94
|
+
"enable": true,
|
95
|
+
"app_name": "TestApp",
|
96
|
+
"severity_level": "debug",
|
97
|
+
"buffer_size": 100,
|
98
|
+
"flush_wait_seconds": 15,
|
99
|
+
"repos":
|
100
|
+
[
|
101
|
+
{
|
102
|
+
"enable": true,
|
103
|
+
"type": "console",
|
104
|
+
"formatter": "delimited_text",
|
105
|
+
"delimiter": "|"
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"enable": true,
|
109
|
+
"type": "File",
|
110
|
+
"file_path": "./log/log.txt",
|
111
|
+
"roll_period": "daily",
|
112
|
+
"roll_size": "1048576",
|
113
|
+
"formatter": "delimited_text",
|
114
|
+
"delimiter": "|"
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"enable": true,
|
118
|
+
"type": "fluentd",
|
119
|
+
"host": "localhost",
|
120
|
+
"port": "8888",
|
121
|
+
"formatter": "json"
|
122
|
+
}
|
123
|
+
]
|
124
|
+
}
|
125
|
+
]
|
126
|
+
}
|
127
|
+
}
|
128
|
+
```
|
84
129
|
- Add new topic to log manager and get the topic instance
|
85
130
|
```ruby
|
86
131
|
# the parameter is the topic name
|
@@ -112,50 +157,58 @@ the result will be:
|
|
112
157
|
- json config file sample
|
113
158
|
```json
|
114
159
|
{
|
115
|
-
"
|
160
|
+
"rta_logger":
|
116
161
|
{
|
117
|
-
"
|
118
|
-
"
|
162
|
+
"default_manager": "develop",
|
163
|
+
"log_managers":
|
119
164
|
[
|
120
165
|
{
|
121
|
-
"
|
122
|
-
"
|
123
|
-
"
|
124
|
-
"
|
125
|
-
"
|
126
|
-
"
|
127
|
-
"
|
128
|
-
"Repos":
|
166
|
+
"manager_name": "develop",
|
167
|
+
"enable": true,
|
168
|
+
"app_name": "TestApp",
|
169
|
+
"severity_level": "debug",
|
170
|
+
"buffer_size": 100,
|
171
|
+
"flush_wait_seconds": 15,
|
172
|
+
"repos":
|
129
173
|
[
|
130
174
|
{
|
131
|
-
"
|
132
|
-
"
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
"Port": 8888
|
175
|
+
"enable": true,
|
176
|
+
"type": "console",
|
177
|
+
"formatter":
|
178
|
+
{
|
179
|
+
"type": "text",
|
180
|
+
"delimiter": "|"
|
181
|
+
}
|
139
182
|
},
|
140
183
|
{
|
141
|
-
"
|
142
|
-
"
|
143
|
-
"
|
144
|
-
"
|
145
|
-
"
|
184
|
+
"enable": false,
|
185
|
+
"type": "file",
|
186
|
+
"file_path": "log.txt",
|
187
|
+
"roll_period": "daily",
|
188
|
+
"roll_size": "1048576",
|
189
|
+
"formatter":
|
190
|
+
{
|
191
|
+
"type": "text",
|
192
|
+
"delimiter": "|"
|
193
|
+
}
|
146
194
|
},
|
147
195
|
{
|
148
|
-
"
|
149
|
-
"
|
150
|
-
"
|
151
|
-
"
|
152
|
-
"
|
196
|
+
"enable": false,
|
197
|
+
"type": "fluentd",
|
198
|
+
"host": "localhost",
|
199
|
+
"port": "8888",
|
200
|
+
"formatter":
|
153
201
|
{
|
154
|
-
"
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
202
|
+
"type": "json"
|
203
|
+
}
|
204
|
+
}
|
205
|
+
],
|
206
|
+
"topics":
|
207
|
+
[
|
208
|
+
{
|
209
|
+
"title": "test",
|
210
|
+
"enable": true,
|
211
|
+
"severity_level": "info"
|
159
212
|
}
|
160
213
|
]
|
161
214
|
}
|
@@ -170,47 +223,64 @@ the result will be:
|
|
170
223
|
log_manager.config_use_json_file('rta_logger_config.json')
|
171
224
|
|
172
225
|
The file structure:
|
173
|
-
-
|
174
|
-
-
|
226
|
+
- rta_logger : the root element of rta_logger json configuration.
|
227
|
+
- default_manager: the name of default log manager config, when there is
|
175
228
|
multiple log manager configuration in Log_Managers array.
|
176
|
-
-
|
229
|
+
- log_managers : the array of LogManagers with different configuration.
|
177
230
|
It is possible to define multiple log manager configurations for differen usages.
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
231
|
+
- manager_name: the name of log manager. It will be used to define the default log manager.
|
232
|
+
- enable: (true/false) The value of this property activate or deactivate entire log manager.
|
233
|
+
- app_name: Application name as the owner of log data.
|
234
|
+
- severity_level: Defines which level of log data will be stored in log repositories.
|
235
|
+
- buffer_size: The memory buffer size (number of buffered log objects) to
|
183
236
|
decread api consumers wait time. when the buffer is full the flush operation will
|
184
237
|
save buffered logs to log repositoies.
|
185
|
-
-
|
238
|
+
- flush_wait_seconds: Time in soconds which log managers wait to flush buffered log objects
|
186
239
|
to log repository.
|
187
|
-
-
|
188
|
-
- Repos: Array of log repositories. It is possible to define multiple log repositories to
|
240
|
+
- repos: Array of log repositories. It is possible to define multiple log repositories to
|
189
241
|
store log data. there are variaty of log repositories and it is possible to
|
190
242
|
add new ones. Each item in Repos array will configure a log repository.
|
243
|
+
Pre-defined types are described below, also it's possible to implement your custome repo type
|
244
|
+
and register it to RTALogger.
|
191
245
|
- Log repository types and config:
|
192
|
-
1-
|
193
|
-
- "
|
194
|
-
- "
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
- "
|
246
|
+
1- console: Show log data in text format on standard out put
|
247
|
+
- "type": "console"
|
248
|
+
- "enable": [true/false] this will activate or deactivate log repository.
|
249
|
+
- "foramtter" is the text, json or any custome defined types as LogRecord formatter
|
250
|
+
- "type": ["text"/"json"] type of formatter
|
251
|
+
- "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
|
252
|
+
if formatter not defined then the json formatter will be used
|
253
|
+
2- file: Store log data in a file.
|
254
|
+
- "type": "console"
|
255
|
+
- "enable": [true/false] this will activate or deactivate log repository.
|
256
|
+
- "file_path": [file path and file name] the path and the name to store log data.
|
257
|
+
- "roll_period": ["daily"/"weekly"/"monthly"] the period to generate new log file.
|
258
|
+
- "roll_size": [bytes] the maximum size of log file to
|
201
259
|
roll file and create the new log file
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
- "
|
209
|
-
- "
|
210
|
-
- "
|
211
|
-
|
212
|
-
- "
|
213
|
-
|
260
|
+
- "foramtter" is the text, json or any custome defined types as LogRecord formatter
|
261
|
+
- "type": ["text"/"json"] type of formatter
|
262
|
+
- "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
|
263
|
+
if formatter not defined then the json formatter will be used
|
264
|
+
3- udp: Send log data over UDP on network.
|
265
|
+
- "type": "udp"
|
266
|
+
- "enable": [true/false] this will activate or deactivate log repository.
|
267
|
+
- "host": IP of the server to send log data.
|
268
|
+
- "port": Port of server to send log data.
|
269
|
+
4- fluentd: send log data to Fluentd Log collector over network using TCP/IP protocol.
|
270
|
+
- "type": "fluentd"
|
271
|
+
- "enable": [true/false] this will activate or deactivate log repository.
|
272
|
+
- "host": IP of the server to send log data.
|
273
|
+
- "port": Port of server to send log data.
|
274
|
+
- "tls_options": TLS configuration to stablish a secure TCP connection to Fluentd Server.
|
275
|
+
- "foramtter" is the text, json or any custome defined types as LogRecord formatter
|
276
|
+
- "type": ["text"/"json"] type of formatter
|
277
|
+
- "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
|
278
|
+
if formatter not defined then the json formatter will be used
|
279
|
+
- topics: This is an optional item. When you need to customize a specific topic severity level or
|
280
|
+
enable value, you can define the settings here.
|
281
|
+
- title: The topic title to customize. (mandatoy).
|
282
|
+
- severity_level: Defines which level of log data will be stored in log repositories.
|
283
|
+
- enable: [true/false] to enable or disable logging process of the topic.
|
214
284
|
```
|
215
285
|
- Some useful features
|
216
286
|
```ruby
|
@@ -218,14 +288,38 @@ the result will be:
|
|
218
288
|
log_manager.app_name = 'myTestApp'
|
219
289
|
|
220
290
|
# update specific topic log level if necessary
|
221
|
-
log_manager.
|
291
|
+
log_manager.update_topic_severity_level(topic_title, RTALogger::SeverityLevel::INFO)
|
292
|
+
|
293
|
+
# update all topics severity level if necessary
|
294
|
+
log_manager.update_all_topics_severity_level(RTALogger::SeverityLevel::INFO)
|
222
295
|
|
223
|
-
#
|
224
|
-
log_manager.
|
296
|
+
# enable or disable specific topic if necessary
|
297
|
+
log_manager.update_topic_enable(topic_title, [true/false])
|
298
|
+
|
299
|
+
# enable or disable all topic if necessary
|
300
|
+
log_manager.update_all_topics_enable([true/false])
|
225
301
|
```
|
226
302
|
- Implement and Expand
|
227
|
-
It is possible to implement new log repositories.
|
228
|
-
|
303
|
+
It is possible to implement new log repositories. There will be fue rules to implement and
|
304
|
+
integrate new customized log repository with RTALogger LogManager.
|
305
|
+
|
306
|
+
1- Define you class inside RTALogger module.
|
307
|
+
|
308
|
+
2- The class should be inherited from 'RTALogger::LogRepository'.
|
309
|
+
|
310
|
+
3- Also appropriate naming convention is necessary.
|
311
|
+
As an example if you are implementing a Console Repo, your class name should be LogRepositoryConsole and
|
312
|
+
your source code in a ruby file and name it log_repository_console.rb
|
313
|
+
|
314
|
+
4- After implementing your own log repository, you should register the class at run-time using the following syntax:
|
315
|
+
```ruby
|
316
|
+
RTALogger::LogFactory.register_log_repository :console, 'log_repository_console.rb'
|
317
|
+
```
|
318
|
+
Another example: LogRepositoryMyCustomizedUdp
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
RTALogger::LogFactory.register_log_repository :my_customized_udp, 'log_repository_my_customized_udp.rb'
|
322
|
+
```
|
229
323
|
Here is 'LogRepositoryConsole' implementation:
|
230
324
|
```ruby
|
231
325
|
require_relative 'log_repository'
|
data/lib/RTALogger/version.rb
CHANGED
@@ -1,20 +1,35 @@
|
|
1
|
-
require_relative 'log_formatter_text'
|
2
|
-
require_relative 'log_formatter_json'
|
3
|
-
|
4
1
|
module RTALogger
|
5
2
|
# Log factory to get new instance of log formatter
|
6
3
|
module LogFactory
|
7
4
|
def self.log_formatter_default
|
8
|
-
|
9
|
-
# RTALogger::LogFormatterText.new
|
5
|
+
create_formatter(:json)
|
10
6
|
end
|
11
7
|
|
12
|
-
def self.
|
13
|
-
|
8
|
+
def self.create_formatter(type, config_json = '')
|
9
|
+
lib_file = @log_formatters[type.to_sym]
|
10
|
+
raise "unregistered formatter class: #{type.to_s}" if lib_file.nil? || lib_file.empty?
|
11
|
+
|
12
|
+
begin
|
13
|
+
load lib_file
|
14
|
+
rescue
|
15
|
+
raise "unable to load formatter class file: #{lib_file}"
|
16
|
+
end
|
17
|
+
|
18
|
+
formatter_class_name = 'RTALogger::' + ('log_formatter_' + type.to_s).split('_').map(&:capitalize).join
|
19
|
+
formatter_class = Object.const_get(formatter_class_name)
|
20
|
+
return nil unless formatter_class
|
21
|
+
result = formatter_class.new
|
22
|
+
|
23
|
+
return result if config_json.empty?
|
24
|
+
result.load_config(config_json) if result.present?
|
25
|
+
return result
|
14
26
|
end
|
15
27
|
|
16
|
-
def self.
|
17
|
-
|
28
|
+
def self.register_log_formatter(type, class_file_name)
|
29
|
+
@log_formatters[type.to_sym] = class_file_name
|
18
30
|
end
|
31
|
+
|
32
|
+
@log_formatters = {:text => 'log_formatter_text.rb',
|
33
|
+
:json => 'log_formatter_json.rb'}
|
19
34
|
end
|
20
35
|
end
|
@@ -1,56 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'log_repository_console'
|
4
|
-
require_relative 'log_repository_file'
|
5
|
-
require_relative 'log_repository_udp'
|
6
|
-
require_relative 'log_repository_fluent'
|
7
|
-
|
8
3
|
module RTALogger
|
9
4
|
# this module generates object instance
|
10
5
|
module LogFactory
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
6
|
+
def self.create_repository(type, config_json = '')
|
7
|
+
lib_file = @log_repositories[type.to_sym]
|
8
|
+
raise "unregistered repository class: #{type.to_s}" if lib_file.nil? || lib_file.empty?
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
begin
|
11
|
+
load lib_file
|
12
|
+
rescue
|
13
|
+
raise "unable to load repository class file: #{lib_file}"
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
16
|
+
# repo_class_name = 'RTALogger::' + type.split('_').map(&:capitalize).join
|
17
|
+
repo_class_name = 'RTALogger::' + ('log_repository_' + type.to_s).split('_').map(&:capitalize).join
|
18
|
+
repo_class = Object.const_get(repo_class_name)
|
19
|
+
return nil unless repo_class
|
20
|
+
result = repo_class.new
|
25
21
|
|
26
|
-
|
27
|
-
|
22
|
+
# result = LogRepository.create type.to_sym
|
23
|
+
return result if config_json.empty?
|
24
|
+
result.load_config(config_json) if result.present?
|
25
|
+
return result
|
28
26
|
end
|
29
27
|
|
30
|
-
def self.
|
31
|
-
|
32
|
-
port = config_json['Port'].nil? ? 4913 : config_json['Port'].to_i
|
33
|
-
::RTALogger::LogFactory.new_log_repository_udp(host, port)
|
28
|
+
def self.register_log_repository(type, class_file_name)
|
29
|
+
@log_repositories[type.to_sym] = class_file_name
|
34
30
|
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def self.load_log_repository_fluent(config_json)
|
41
|
-
host = config_json['Host'].to_s
|
42
|
-
port = config_json['Port'].to_s
|
43
|
-
tls_options = config_json['TLS_Options']
|
44
|
-
::RTALogger::LogFactory.new_log_repository_fluent(host, port, tls_options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.create_repository(type, config_json)
|
48
|
-
result = nil
|
49
|
-
result = new_log_repository_console if type.to_s.casecmp('Console').zero?
|
50
|
-
result = load_log_repository_file(config_json) if type.to_s.casecmp('File').zero?
|
51
|
-
result = load_log_repository_udp(config_json) if type.to_s.casecmp('UDP').zero?
|
52
|
-
result = load_log_repository_fluent(config_json) if type.to_s.casecmp('Fluentd').zero?
|
53
|
-
result
|
54
|
-
end
|
32
|
+
@log_repositories = {:console => 'log_repository_console.rb',
|
33
|
+
:file => 'log_repository_file.rb',
|
34
|
+
:udp => 'log_repository_upd.rb',
|
35
|
+
:fluentd => 'log_repository_fluetnd.rb'}
|
55
36
|
end
|
56
37
|
end
|
data/lib/log_factory_topic.rb
CHANGED
@@ -5,8 +5,8 @@ require_relative 'log_topic'
|
|
5
5
|
module RTALogger
|
6
6
|
# this module generates object instance
|
7
7
|
module LogFactory
|
8
|
-
def self.new_log_topic(log_manager,
|
9
|
-
LogTopic.new(log_manager,
|
8
|
+
def self.new_log_topic(log_manager, title, level = WARN, enable = true)
|
9
|
+
LogTopic.new(log_manager, title, level, enable)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/log_formatter.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
+
# Log Formatter base class
|
1
2
|
module RTALogger
|
2
|
-
# Log Formatter base class
|
3
3
|
class LogFormatter
|
4
|
+
def initialize
|
5
|
+
@delimiter = '|'
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :delimiter
|
9
|
+
|
10
|
+
def load_config(config_json)
|
11
|
+
@delimiter = config_json['delimiter'].nil? ? true : config_json['delimiter']
|
12
|
+
end
|
13
|
+
|
4
14
|
def format(log_record)
|
5
15
|
log_record.to_s
|
6
16
|
end
|
data/lib/log_formatter_json.rb
CHANGED
data/lib/log_formatter_text.rb
CHANGED
@@ -4,15 +4,15 @@ module RTALogger
|
|
4
4
|
# text formatter which receive log_record and
|
5
5
|
# returns it's data as delimited text string
|
6
6
|
class LogFormatterText < LogFormatter
|
7
|
-
def format(log_record
|
7
|
+
def format(log_record)
|
8
8
|
return '' unless log_record
|
9
9
|
|
10
10
|
result = log_record.occurred_at.strftime('%F %H:%M:%S:%3N')
|
11
|
-
result << delimiter << log_record.app_name
|
12
|
-
result << delimiter << log_record.topic_title
|
13
|
-
result << delimiter << log_record.context_id
|
14
|
-
result << delimiter << log_record.severity
|
15
|
-
result << delimiter << log_record.message.join(' ').gsub(delimiter, '$<$')
|
11
|
+
result << @delimiter << log_record.app_name
|
12
|
+
result << @delimiter << log_record.topic_title
|
13
|
+
result << @delimiter << log_record.context_id
|
14
|
+
result << @delimiter << log_record.severity
|
15
|
+
result << @delimiter << log_record.message.join(' ').gsub(delimiter, '$<$')
|
16
16
|
|
17
17
|
result
|
18
18
|
end
|
data/lib/log_manager.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'thread'
|
3
3
|
require 'singleton'
|
4
|
+
require 'json'
|
5
|
+
require 'json/version'
|
6
|
+
require 'json/generic_object'
|
4
7
|
require_relative 'log_factory_propagator'
|
5
8
|
require_relative 'log_factory_repository'
|
6
9
|
require_relative 'log_factory_topic'
|
7
|
-
require_relative '
|
10
|
+
require_relative 'severity_level'
|
11
|
+
require 'jbuilder'
|
8
12
|
|
9
13
|
# the module will contain all logger requirements
|
10
14
|
module RTALogger
|
11
15
|
# the class is the main class
|
12
16
|
class LogManager
|
13
17
|
include Singleton
|
14
|
-
include
|
18
|
+
include SeverityLevel
|
15
19
|
include RTALogger::LogFactory
|
16
20
|
|
17
21
|
def initialize
|
18
22
|
@enable = true
|
19
|
-
@
|
20
|
-
@
|
23
|
+
@name = 'default_log_manager'
|
24
|
+
@app_name = ENV.fetch('RTA_LOGGER_APP_NAME', 'unknown_app')
|
25
|
+
@severity_level = ENV.fetch('RTA_LOGGER_SEVERITY_LEVEL', WARN)
|
26
|
+
@config_file_name = ''
|
21
27
|
@topic_semaphore = Mutex.new
|
22
28
|
@log_semaphore = Mutex.new
|
23
|
-
@buffer_size = ENV.fetch('
|
29
|
+
@buffer_size = ENV.fetch('RTA_LOGGER_BUFFER_SIZE', 100)
|
24
30
|
@flush_size = @buffer_size * 20 / 100
|
25
|
-
@flush_wait_time = ENV.fetch('
|
31
|
+
@flush_wait_time = ENV.fetch('RTA_LOGGER_FLUSH_WAIT_SECONDS', 15)
|
26
32
|
@topics = {}
|
27
33
|
@log_records = []
|
28
34
|
@propagator = LogFactory.new_log_propagator
|
@@ -36,13 +42,25 @@ module RTALogger
|
|
36
42
|
@flush_scheduler.run
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
|
-
|
45
|
+
attr_reader :name
|
46
|
+
attr_accessor :enable
|
47
|
+
attr_accessor :app_name
|
48
|
+
attr_reader :propagator
|
49
|
+
attr_accessor :default_severity_level
|
50
|
+
attr_accessor :buffer_size
|
51
|
+
attr_reader :flush_size
|
52
|
+
attr_accessor :flush_wait_time
|
53
|
+
attr_reader :topics
|
54
|
+
attr_reader :config_file_name
|
55
|
+
|
56
|
+
def config_use_json_file(file_name, manager_name = '')
|
57
|
+
config_json = load_config_from_json_file(file_name, manager_name)
|
58
|
+
@config_file_name = file_name if config_json
|
41
59
|
apply_config(config_json)
|
42
60
|
rescue StandardError => e
|
43
61
|
puts e.message
|
44
62
|
@propagator.drop_all_repositories
|
45
|
-
@propagator.add_log_repository(LogFactory.
|
63
|
+
@propagator.add_log_repository(LogFactory.create_repository(:console))
|
46
64
|
end
|
47
65
|
|
48
66
|
def config_use_json_string(config_string, manager_name = '')
|
@@ -51,21 +69,15 @@ module RTALogger
|
|
51
69
|
rescue StandardError => e
|
52
70
|
puts e.message
|
53
71
|
@propagator.drop_all_repositories
|
54
|
-
@propagator.add_log_repository(LogFactory.
|
72
|
+
@propagator.add_log_repository(LogFactory.create_repository(:console))
|
55
73
|
end
|
56
74
|
|
57
|
-
|
58
|
-
attr_accessor :app_name
|
59
|
-
attr_reader :propagator
|
60
|
-
attr_reader :default_log_level
|
61
|
-
|
62
|
-
def add_topic(topic_title, log_level = @default_log_level)
|
75
|
+
def add_topic(title, severity_level = @default_severity_level, enable = true)
|
63
76
|
@topic_semaphore.synchronize {
|
64
|
-
@topics[
|
77
|
+
@topics[title.to_sym] ||= LogFactory.new_log_topic(self, title, severity_level, enable)
|
65
78
|
}
|
66
79
|
|
67
|
-
@topics[
|
68
|
-
@topics[topic_title.to_sym]
|
80
|
+
@topics[title.to_sym]
|
69
81
|
end
|
70
82
|
|
71
83
|
def add_log(log_record)
|
@@ -74,52 +86,100 @@ module RTALogger
|
|
74
86
|
check_for_flush
|
75
87
|
end
|
76
88
|
|
77
|
-
def
|
78
|
-
@topic_semaphore.synchronize { @topics[topic].
|
89
|
+
def update_topic_enable(topic, enable = true)
|
90
|
+
@topic_semaphore.synchronize { @topics[topic.to_sym].enable = enable if @topics[topic.to_sym] }
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_all_topics_enable(enable = true)
|
94
|
+
@topic_semaphore.synchronize { @topics.keys.each { |topic| @topics[topic].enable = enable } }
|
95
|
+
end
|
96
|
+
|
97
|
+
def update_topic_severity_level(topic, severity_level = WARN)
|
98
|
+
@topic_semaphore.synchronize { @topics[topic.to_sym].severity_level = severity_level if @topics[topic.to_sym] }
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_all_topics_severity_level(severity_level = WARN)
|
102
|
+
@topic_semaphore.synchronize { @topics.keys.each { |topic| @topics[topic].severity_level = severity_level } }
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_builder
|
106
|
+
@topic_semaphore.synchronize do
|
107
|
+
jb = Jbuilder.new do |json|
|
108
|
+
json.name name
|
109
|
+
json.enable enable
|
110
|
+
json.app_name app_name
|
111
|
+
json.config_file_name config_file_name
|
112
|
+
json.default_severity_level default_severity_level
|
113
|
+
json.buffer_size buffer_size
|
114
|
+
json.flush_size flush_size
|
115
|
+
json.flush_wait_time flush_wait_time
|
116
|
+
json.topics do
|
117
|
+
json.array! topics.keys.collect { |topic_key| @topics[topic_key].to_builder.attributes! }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
jb
|
122
|
+
end
|
79
123
|
end
|
80
124
|
|
81
|
-
def
|
82
|
-
|
125
|
+
def reveal_config
|
126
|
+
to_builder.target!
|
83
127
|
end
|
84
128
|
|
85
129
|
private
|
86
130
|
|
87
131
|
def load_config_from_json_file(config_file_name, manager_name = '')
|
88
132
|
config_file = File.open config_file_name
|
89
|
-
config_json = JSON.load
|
133
|
+
config_json = ::JSON.load(config_file)
|
90
134
|
config_json = extract_config(config_json, manager_name)
|
91
135
|
config_json
|
92
136
|
end
|
93
137
|
|
94
138
|
def load_config_from_json_string(config_string, manager_name = '')
|
95
|
-
config_json = JSON.parse(config_string)
|
139
|
+
config_json = ::JSON.parse(config_string)
|
96
140
|
config_json = extract_config(config_json, manager_name)
|
97
141
|
config_json
|
98
142
|
end
|
99
143
|
|
100
144
|
def extract_config(json_data, manager_name = '')
|
101
|
-
config_json = json_data['
|
145
|
+
config_json = json_data['rta_logger']
|
102
146
|
raise 'RTALogger configuration not found!' unless config_json
|
103
|
-
raise 'Log_Managers section does not exists json configuration' unless config_json['
|
104
|
-
raise 'No config manager defined in json configuration' unless config_json['
|
105
|
-
manager_name = config_json['
|
147
|
+
raise 'Log_Managers section does not exists json configuration' unless config_json['log_managers']
|
148
|
+
raise 'No config manager defined in json configuration' unless config_json['log_managers'].count.positive?
|
149
|
+
manager_name = config_json['default_manager'] if manager_name.empty?
|
106
150
|
unless manager_name.to_s.strip.empty?
|
107
|
-
config_json = config_json['
|
151
|
+
config_json = config_json['log_managers'].find { |item| item['manager_name'] == manager_name }
|
108
152
|
end
|
109
|
-
config_json ||= config_json['
|
153
|
+
config_json ||= config_json['log_managers'][0]
|
110
154
|
raise 'Unable to extract RTA Log Manager configuration!' unless config_json
|
155
|
+
@name = manager_name if config_json
|
111
156
|
config_json
|
112
157
|
end
|
113
158
|
|
114
159
|
def apply_config(config_json)
|
115
160
|
raise 'json config not available' unless config_json
|
116
|
-
@enable = config_json['
|
117
|
-
@app_name = config_json['
|
118
|
-
@
|
119
|
-
@
|
120
|
-
@flush_wait_time = config_json['
|
161
|
+
@enable = config_json['enable'].nil? ? true : config_json['enable']
|
162
|
+
@app_name = config_json['app_name'] unless config_json['app_name'].empty?
|
163
|
+
@default_severity_level = parse_severity_level_to_i(config_json['severity_level']) if config_json['severity_level']
|
164
|
+
@buffer_size = config_json['buffer_size'] if config_json['buffer_size']
|
165
|
+
@flush_wait_time = config_json['flush_wait_seconds'] if config_json['flush_wait_seconds']
|
121
166
|
@propagator.drop_all_repositories
|
122
|
-
config_json
|
167
|
+
apply_config_repos(config_json)
|
168
|
+
apply_config_topics(config_json)
|
169
|
+
end
|
170
|
+
|
171
|
+
def apply_config_repos(config_json)
|
172
|
+
config_json['repos']&.each { |item| @propagator.load_log_repository(item) }
|
173
|
+
end
|
174
|
+
|
175
|
+
def apply_config_topics(config_json)
|
176
|
+
config_json['topics']&.each do |topic|
|
177
|
+
next unless topic['title']
|
178
|
+
result_topic = add_topic(topic['title'])
|
179
|
+
next unless result_topic
|
180
|
+
result_topic.severity_level = parse_severity_level_to_i topic['severity_level'] if topic['severity_level']
|
181
|
+
result_topic.enable = topic['enable'] if topic['enable']
|
182
|
+
end
|
123
183
|
end
|
124
184
|
|
125
185
|
def initialize_flush_scheduler
|
@@ -153,7 +213,7 @@ module RTALogger
|
|
153
213
|
|
154
214
|
def flush_all
|
155
215
|
@log_semaphore.synchronize do
|
156
|
-
@log_records[0...@log_records.count].each { |log|
|
216
|
+
@log_records[0...@log_records.count].each { |log| propagate(log) }
|
157
217
|
@log_records.clear
|
158
218
|
end
|
159
219
|
@propagator.propagate
|
@@ -162,5 +222,6 @@ module RTALogger
|
|
162
222
|
def propagate(log_record)
|
163
223
|
@propagator.add_log(log_record)
|
164
224
|
end
|
225
|
+
|
165
226
|
end
|
166
227
|
end
|
data/lib/log_propagator.rb
CHANGED
@@ -19,9 +19,9 @@ module RTALogger
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def load_log_repository(config_json)
|
22
|
-
type = config_json['
|
22
|
+
type = config_json['type']
|
23
23
|
return if type.to_s.strip.empty?
|
24
|
-
enable = config_json['
|
24
|
+
enable = config_json['enable'].nil? ? true : config_json['enable']
|
25
25
|
return unless enable
|
26
26
|
|
27
27
|
log_repository = ::RTALogger::LogFactory.create_repository(type, config_json)
|
data/lib/log_record.rb
CHANGED
data/lib/log_repository.rb
CHANGED
@@ -7,6 +7,23 @@ module RTALogger
|
|
7
7
|
@enable = true
|
8
8
|
end
|
9
9
|
|
10
|
+
# @@sub_classes = {}
|
11
|
+
|
12
|
+
# def self.create type
|
13
|
+
# requested_class = @@sub_classes[type]
|
14
|
+
# if requested_class
|
15
|
+
# requested_class.new
|
16
|
+
# else
|
17
|
+
# raise "Bad log repository type: #{type}"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def self.register repository_name
|
22
|
+
# @@sub_classes[repository_name] = self
|
23
|
+
# end
|
24
|
+
|
25
|
+
attr_accessor :enable
|
26
|
+
|
10
27
|
def add_log_records(items)
|
11
28
|
return 0 unless @enable
|
12
29
|
@semaphore.synchronize do
|
@@ -15,7 +32,14 @@ module RTALogger
|
|
15
32
|
flush_and_clear
|
16
33
|
end
|
17
34
|
|
18
|
-
|
35
|
+
def load_config(config_json)
|
36
|
+
@enable = config_json['enable'].nil? ? true : config_json['enable']
|
37
|
+
|
38
|
+
formatter_config = config_json['formatter']
|
39
|
+
if formatter_config && formatter_config['type']
|
40
|
+
@formatter = LogFactory.create_formatter(formatter_config['type'], formatter_config)
|
41
|
+
end
|
42
|
+
end
|
19
43
|
|
20
44
|
protected
|
21
45
|
|
data/lib/log_repository_file.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require_relative 'log_repository'
|
3
|
-
require_relative 'log_factory_file_logger'
|
4
3
|
require_relative 'log_factory_log_formatter'
|
5
4
|
|
6
5
|
module RTALogger
|
@@ -8,12 +7,32 @@ module RTALogger
|
|
8
7
|
class LogRepositoryFile < LogRepository
|
9
8
|
def initialize(file_path = 'log.txt', period = 'daily', shift_size = 1_048_576)
|
10
9
|
super()
|
11
|
-
@file_logger =
|
10
|
+
@file_logger = create_ruby_logger(file_path, period, shift_size)
|
12
11
|
@formatter = RTALogger::LogFactory.log_formatter_default
|
13
12
|
end
|
14
13
|
|
14
|
+
def load_config(config_json)
|
15
|
+
super
|
16
|
+
|
17
|
+
file_path = config_json['file_path'].to_s
|
18
|
+
period = config_json['roll_period'].to_s
|
19
|
+
shift_size = config_json['roll_size'].nil? ? 1_048_576 : config_json['roll_size'].to_i
|
20
|
+
@file_logger = create_ruby_logger(file_path, period, shift_size)
|
21
|
+
end
|
22
|
+
|
23
|
+
# register :file
|
24
|
+
|
15
25
|
protected
|
16
26
|
|
27
|
+
def create_ruby_logger(file_path, period, shift_size)
|
28
|
+
ruby_logger = Logger.new(file_path, period, shift_size)
|
29
|
+
ruby_logger.level = Logger::Severity::DEBUG
|
30
|
+
ruby_logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
31
|
+
"#{msg}\n"
|
32
|
+
end
|
33
|
+
ruby_logger
|
34
|
+
end
|
35
|
+
|
17
36
|
def flush_and_clear
|
18
37
|
semaphore.synchronize do
|
19
38
|
@log_records.each { |log_record| @file_logger.debug(@formatter.format(log_record)) }
|
@@ -5,15 +5,32 @@ module RTALogger
|
|
5
5
|
class LogRepositoryFluent < LogRepository
|
6
6
|
def initialize(host = 'localhost', port = 24224, tls_options = nil)
|
7
7
|
super()
|
8
|
-
@host = host
|
9
|
-
@port = port
|
10
|
-
@tls_options = tls_options
|
11
8
|
@formatter = RTALogger::LogFactory.log_formatter_json
|
12
|
-
|
13
|
-
|
9
|
+
@fluent_logger = create_fluentd_logger(host, port, tls_options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_config(config_json)
|
13
|
+
super
|
14
|
+
|
15
|
+
host = config_json['host'].to_s
|
16
|
+
port = config_json['port'].to_s
|
17
|
+
tls_options = config_json['tls_options']
|
18
|
+
|
19
|
+
@fluent_logger = create_fluentd_logger(host, port, tls_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# register :fluentd
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def create_fluentd_logger(host, port, tls_options)
|
27
|
+
unless tls_options
|
28
|
+
fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, :host => host, :port => port, :use_nonblock => true, :wait_writeable => false)
|
14
29
|
else
|
15
|
-
|
30
|
+
fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, :host => host, :port => port, :tls_options => tls_options, :use_nonblock => true, :wait_writeable => false)
|
16
31
|
end
|
32
|
+
|
33
|
+
fluent_logger
|
17
34
|
end
|
18
35
|
|
19
36
|
def flush_and_clear
|
data/lib/log_repository_udp.rb
CHANGED
@@ -5,18 +5,26 @@ module RTALogger
|
|
5
5
|
class LogRepositoryUDP < LogRepository
|
6
6
|
def initialize(host = '127.0.0.1', port = 4913)
|
7
7
|
super()
|
8
|
-
@
|
9
|
-
@
|
8
|
+
@udp_socket = UDPSocket.new
|
9
|
+
@udp_socket.bind(host, port)
|
10
10
|
end
|
11
11
|
|
12
|
+
def load_config(config_json)
|
13
|
+
super
|
14
|
+
|
15
|
+
host = config_json['host'].to_s
|
16
|
+
port = config_json['port'].nil? ? 4913 : config_json['port'].to_i
|
17
|
+
@udp_socket = UDPSocket.new
|
18
|
+
@udp_socket.bind(host, port)
|
19
|
+
end
|
20
|
+
|
21
|
+
# register :udp
|
22
|
+
|
12
23
|
protected
|
13
24
|
|
14
25
|
def flush_and_clear
|
15
26
|
semaphore.synchronize do
|
16
|
-
|
17
|
-
u1.bind(@host, @port)
|
18
|
-
@log_records.each { |log_record| u1.send log_record.to_s, 0, @host, @port }
|
19
|
-
u1.close
|
27
|
+
@log_records.each { |log_record| @udp_socket.send @formatter.format(log_record), 0, @host, @port }
|
20
28
|
end
|
21
29
|
super
|
22
30
|
end
|
data/lib/log_topic.rb
CHANGED
@@ -1,49 +1,59 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'severity_level'
|
2
2
|
require_relative 'log_factory_record'
|
3
|
+
require 'jbuilder'
|
3
4
|
|
4
5
|
module RTALogger
|
5
6
|
# the main class to logging data as topic
|
6
7
|
class LogTopic
|
7
|
-
include
|
8
|
+
include SeverityLevel
|
8
9
|
include RTALogger::LogFactory
|
9
10
|
|
10
|
-
def initialize(log_manager,
|
11
|
+
def initialize(log_manager, title, severity_level = WARN, enable = true)
|
11
12
|
# Logger logger = Logger.new(Logger::DEBUG)
|
12
|
-
@enable =
|
13
|
+
@enable = enable
|
13
14
|
@log_manager = log_manager
|
14
|
-
@
|
15
|
-
@
|
15
|
+
@title = title.to_s.dup
|
16
|
+
@severity_level = severity_level
|
16
17
|
end
|
17
18
|
|
18
19
|
attr_accessor :enable
|
19
20
|
attr_reader :log_manager
|
20
|
-
attr_reader :
|
21
|
-
attr_accessor :
|
21
|
+
attr_reader :title
|
22
|
+
attr_accessor :severity_level
|
22
23
|
|
23
24
|
def debug(context_id, *message)
|
24
|
-
add(context_id, DEBUG, message) if @
|
25
|
+
add(context_id, DEBUG, message) if @severity_level.to_i <= DEBUG.to_i
|
25
26
|
end
|
26
27
|
|
27
28
|
def info(context_id, *message)
|
28
|
-
add(context_id, INFO, message) if @
|
29
|
+
add(context_id, INFO, message) if @severity_level.to_i <= INFO.to_i
|
29
30
|
end
|
30
31
|
|
31
32
|
def warning(context_id, *message)
|
32
|
-
add(context_id, WARN, message) if @
|
33
|
+
add(context_id, WARN, message) if @severity_level.to_i <= WARN.to_i
|
33
34
|
end
|
34
35
|
|
35
36
|
def error(context_id, *message)
|
36
|
-
add(context_id, ERROR, message) if @
|
37
|
+
add(context_id, ERROR, message) if @severity_level.to_i <= ERROR.to_i
|
37
38
|
end
|
38
39
|
|
39
40
|
def fatal(context_id, *message)
|
40
|
-
add(context_id, FATAL, message) if @
|
41
|
+
add(context_id, FATAL, message) if @severity_level.to_i <= FATAL.to_i
|
41
42
|
end
|
42
43
|
|
43
44
|
def unknown(context_id, *message)
|
44
|
-
add(context_id, UNKNOWN, message) if @
|
45
|
+
add(context_id, UNKNOWN, message) if @severity_level.to_i <= UNKNOWN.to_i
|
45
46
|
end
|
46
47
|
|
48
|
+
def to_builder
|
49
|
+
jb = Jbuilder.new do |json|
|
50
|
+
json.title title
|
51
|
+
json.severity_level parse_severity_level_to_s(severity_level)
|
52
|
+
json.enable enable
|
53
|
+
end
|
54
|
+
|
55
|
+
jb
|
56
|
+
end
|
47
57
|
private
|
48
58
|
|
49
59
|
def add(context_id, severity, *message)
|
data/lib/rta_logger_config.json
CHANGED
@@ -1,35 +1,56 @@
|
|
1
1
|
{
|
2
|
-
"
|
2
|
+
"rta_logger":
|
3
3
|
{
|
4
|
-
"
|
5
|
-
"
|
4
|
+
"default_manager": "develop",
|
5
|
+
"log_managers":
|
6
6
|
[
|
7
7
|
{
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"Repos":
|
8
|
+
"manager_name": "develop",
|
9
|
+
"enable": true,
|
10
|
+
"app_name": "TestApp",
|
11
|
+
"severity_level": "debug",
|
12
|
+
"buffer_size": 100,
|
13
|
+
"flush_wait_seconds": 15,
|
14
|
+
"repos":
|
16
15
|
[
|
17
16
|
{
|
18
|
-
"
|
19
|
-
"
|
17
|
+
"enable": true,
|
18
|
+
"type": "console",
|
19
|
+
"formatter":
|
20
|
+
{
|
21
|
+
"type": "text",
|
22
|
+
"delimiter": "|"
|
23
|
+
}
|
20
24
|
},
|
21
25
|
{
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
26
|
+
"enable": true,
|
27
|
+
"type": "file",
|
28
|
+
"file_path": "log.txt",
|
29
|
+
"roll_period": "daily",
|
30
|
+
"roll_size": "1048576",
|
31
|
+
"formatter":
|
32
|
+
{
|
33
|
+
"type": "text",
|
34
|
+
"delimiter": "|"
|
35
|
+
}
|
27
36
|
},
|
28
37
|
{
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
38
|
+
"enable": true,
|
39
|
+
"type": "fluentd",
|
40
|
+
"host": "localhost",
|
41
|
+
"port": "8888",
|
42
|
+
"formatter":
|
43
|
+
{
|
44
|
+
"type": "json"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"topics":
|
49
|
+
[
|
50
|
+
{
|
51
|
+
"title": "test",
|
52
|
+
"enable": true,
|
53
|
+
"severity_level": "WARN"
|
33
54
|
}
|
34
55
|
]
|
35
56
|
}
|
data/lib/sample.rb
CHANGED
@@ -4,6 +4,9 @@ require_relative 'log_factory_repository'
|
|
4
4
|
controller_name = 'test_controller'
|
5
5
|
userID = 5
|
6
6
|
|
7
|
+
|
8
|
+
# RTALogger::LogFactory.register_log_repository :console, 'log_repository_console.rb'
|
9
|
+
|
7
10
|
# create log manager instance
|
8
11
|
# this could be a global variable declared in application level
|
9
12
|
log_manager = RTALogger::LogFactory.log_manager_instance
|
@@ -21,6 +24,9 @@ log_manager.config_use_json_file('rta_logger_config.json')
|
|
21
24
|
# use this api to get a new log topic instance
|
22
25
|
# this api could be called in entry point of each service or class initialize method
|
23
26
|
topic = log_manager.add_topic(controller_name)
|
27
|
+
test_topic = log_manager.add_topic('test')
|
28
|
+
# test_topic.severity_level = ::RTALogger::SeverityLevel::FATAL
|
29
|
+
# test_topic.enable = false
|
24
30
|
|
25
31
|
# add log information to log topic
|
26
32
|
topic.debug(userID, 'Controller Name=', controller_name, 'debug')
|
@@ -30,8 +36,13 @@ topic.error(userID, 'Controller Name=', controller_name, 'error')
|
|
30
36
|
topic.fatal(userID, 'Controller Name=', controller_name, 'fatal')
|
31
37
|
topic.unknown(userID, 'Controller Name=', controller_name, 'unknown')
|
32
38
|
|
39
|
+
test_topic.error(userID, 'test_topic', 'error')
|
40
|
+
test_topic.fatal(userID, 'test_topic', 'fatal')
|
41
|
+
|
42
|
+
puts log_manager.reveal_config
|
43
|
+
|
33
44
|
# update specific topic log level if necessary
|
34
|
-
# log_manager.update_topic_level(controller_name, RTALogger::
|
45
|
+
# log_manager.update_topic_level(controller_name, RTALogger::SeverityLevel::INFO)
|
35
46
|
|
36
47
|
# update all topics log level if necessary
|
37
|
-
# log_manager.
|
48
|
+
# log_manager.update_all_topics_severity_level(RTALogger::SeverityLevel::INFO)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RTALogger
|
2
|
+
# Logging severity.
|
3
|
+
module SeverityLevel
|
4
|
+
# Low-level information, mostly for developers.
|
5
|
+
DEBUG = 0
|
6
|
+
# Generic (useful) information about system operation.
|
7
|
+
INFO = 1
|
8
|
+
# A warning.
|
9
|
+
WARN = 2
|
10
|
+
# A handleable error condition.
|
11
|
+
ERROR = 3
|
12
|
+
# An un-handleable error that results in a program crash.
|
13
|
+
FATAL = 4
|
14
|
+
# An unknown message that should always be logged.
|
15
|
+
UNKNOWN = 5
|
16
|
+
|
17
|
+
|
18
|
+
def parse_severity_level_to_i(severity_level)
|
19
|
+
return severity_level if severity_level.is_a? ::Integer
|
20
|
+
|
21
|
+
case severity_level.upcase
|
22
|
+
when 'DEBUG'
|
23
|
+
0
|
24
|
+
when 'INFO'
|
25
|
+
1
|
26
|
+
when 'INFORMATIONّٔ'
|
27
|
+
1
|
28
|
+
when 'WARN'
|
29
|
+
2
|
30
|
+
when 'WARNING'
|
31
|
+
2
|
32
|
+
when 'ERROR'
|
33
|
+
3
|
34
|
+
when 'FATAL'
|
35
|
+
4
|
36
|
+
when 'UNKNOWN'
|
37
|
+
5
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_severity_level_to_s(severity_level)
|
42
|
+
return severity_level if severity_level.is_a? ::String
|
43
|
+
|
44
|
+
case severity_level.to_i
|
45
|
+
when 0
|
46
|
+
'DEBUG'
|
47
|
+
when 1
|
48
|
+
'INFO'
|
49
|
+
when 2
|
50
|
+
'WARN'
|
51
|
+
when 3
|
52
|
+
'ERROR'
|
53
|
+
when 4
|
54
|
+
'FATAL'
|
55
|
+
when 5
|
56
|
+
'UNKNOWN'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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: 0.
|
4
|
+
version: 1.0.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: 2020-12-
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluent-logger
|
@@ -68,7 +68,6 @@ files:
|
|
68
68
|
- bin/setup
|
69
69
|
- lib/RTALogger.rb
|
70
70
|
- lib/RTALogger/version.rb
|
71
|
-
- lib/log_factory_file_logger.rb
|
72
71
|
- lib/log_factory_log_formatter.rb
|
73
72
|
- lib/log_factory_manager.rb
|
74
73
|
- lib/log_factory_propagator.rb
|
@@ -86,10 +85,10 @@ files:
|
|
86
85
|
- lib/log_repository_file.rb
|
87
86
|
- lib/log_repository_fluent.rb
|
88
87
|
- lib/log_repository_udp.rb
|
89
|
-
- lib/log_severity.rb
|
90
88
|
- lib/log_topic.rb
|
91
89
|
- lib/rta_logger_config.json
|
92
90
|
- lib/sample.rb
|
91
|
+
- lib/severity_level.rb
|
93
92
|
homepage: https://github.com/BBahrainy/RTALogger.git
|
94
93
|
licenses:
|
95
94
|
- MIT
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
module RTALogger
|
6
|
-
# this module generates object instance
|
7
|
-
module LogFactory
|
8
|
-
def self.new_file_logger(file_path = 'log.txt', period = 'daily', shift_size = 1_048_576)
|
9
|
-
@ruby_logger = Logger.new(file_path, period, shift_size)
|
10
|
-
@ruby_logger.level = Logger::Severity::DEBUG
|
11
|
-
@ruby_logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
12
|
-
"#{msg}\n"
|
13
|
-
end
|
14
|
-
@ruby_logger
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/log_severity.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module RTALogger
|
2
|
-
# Logging severity.
|
3
|
-
module LogSeverity
|
4
|
-
# Low-level information, mostly for developers.
|
5
|
-
DEBUG = 0
|
6
|
-
# Generic (useful) information about system operation.
|
7
|
-
INFO = 1
|
8
|
-
# A warning.
|
9
|
-
WARN = 2
|
10
|
-
# A handleable error condition.
|
11
|
-
ERROR = 3
|
12
|
-
# An un-handleable error that results in a program crash.
|
13
|
-
FATAL = 4
|
14
|
-
# An unknown message that should always be logged.
|
15
|
-
UNKNOWN = 5
|
16
|
-
end
|
17
|
-
end
|