RTALogger 1.1.0 → 1.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +25 -27
- data/lib/RTALogger/version.rb +1 -1
- data/lib/log_formatter_json.rb +4 -1
- data/lib/log_formatter_text.rb +5 -2
- data/lib/log_manager.rb +21 -7
- data/lib/rta_logger_config.json +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b037c1dbb6f51228afd43cfc7e576e86a7e46e711b96cedaaeb9a5b3e5f3f1ec
|
4
|
+
data.tar.gz: d1e2fb9ee4cddf0b221b0ec9c471117953387c502337e3d438b82348ce4111ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe26e02fcdb17eb44f56644469f7061a925f5dfdc25afcde968b1d910eb5f25a13a49e25afeec8898e78eb7398bbcabe53fca3b7ca98dc85afdeae304ba12a0
|
7
|
+
data.tar.gz: 11fdcff4f789f1eb739cd307c9f60c52b7f6a2816caa60699b0d1f607fba0a3cf7619e58dd17d6817b4711ba35f4998585e64a8d0f099142f8c3009210220759
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,26 +7,24 @@ All log manager's main features are configable through a json config file.
|
|
7
7
|
|
8
8
|
Main purposes of developing this gem are:
|
9
9
|
- Creating standard logging API to seperate application from existing variety of loggers.
|
10
|
-
- Wrapping around existing loggers
|
11
|
-
- Make it possible to easily replace a logger component with
|
12
|
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
- No interrupt or wait time for log consumer modules.
|
10
|
+
- Wrapping around existing loggers to get advantage of different loggers at the same time.
|
11
|
+
- Make it possible to easily replace a logger component with new one without any changes in the consumer application.(for example Rails standard Logger with Fluentd)
|
12
|
+
- Creating easy to use logger interface for developers.
|
13
|
+
- Apply some rules and restrictions about log structure and data format, which prevents chaos in application's log information.
|
14
|
+
- No interrupt, wait time or overhead for log consumer modules.
|
16
15
|
- Utilize multiple log repositories at the same time in background (Console, File, UDP, FluentD, etc.)
|
17
|
-
- Make it possible to implement
|
16
|
+
- Make it possible to implement customize log repositories.
|
18
17
|
|
19
18
|
Main Features:
|
20
19
|
- Creating multiple log manager instances with different configuration is possible entire application.
|
21
20
|
- Each log manager instance could be configured via a json file.
|
22
21
|
- Each log manager instance could be config to use multiple log repositories such as Console, File, UDP, Fluentd.
|
23
22
|
- Runtime configurations could be applied through log manager APIs.
|
24
|
-
- By using multi threading
|
25
|
-
all logging process will handled in seperated thread.
|
23
|
+
- By using multi threading and buffering techniques, all logging process will handled in seperated thread.
|
26
24
|
So the log consumer modules should not be wait for log manager to finish the logging task.
|
27
25
|
- Multiple standard log severity levels are available through topic APIs (debug, info, warning, error, fatal, unknown)
|
28
26
|
- Main features could be set and manipulate through json configuration file.
|
29
|
-
- And at the end, it is easy to use for ruby
|
27
|
+
- And at the end, it is easy to use for ruby developers.
|
30
28
|
|
31
29
|
## Installation
|
32
30
|
|
@@ -36,11 +34,11 @@ Add this line to your application's Gemfile:
|
|
36
34
|
gem 'RTALogger'
|
37
35
|
```
|
38
36
|
|
39
|
-
|
37
|
+
Then execute:
|
40
38
|
|
41
39
|
$ bundle install
|
42
40
|
|
43
|
-
Or install it yourself
|
41
|
+
Or install it yourself via following command:
|
44
42
|
|
45
43
|
$ gem install RTALogger
|
46
44
|
|
@@ -51,12 +49,12 @@ To add gem to your rails application:
|
|
51
49
|
## Usage
|
52
50
|
#### RTA Log Data Structure
|
53
51
|
To use log manager APIs, first step is to have a quick review on Log Data Structure
|
54
|
-
- Application: The root of each log data record is Application, which specify the log data owner application.
|
52
|
+
- Application: The root of each log data record is the Application name, which specify the log data owner application.
|
55
53
|
- Topic: By adding multiple topics to log manager you can categorize log data in logical topics.
|
56
54
|
- Context: Under each topic, one or multiple contexts (in one level) could be defined.
|
57
|
-
- As an instance
|
58
|
-
|
59
|
-
- The next step is log severity level, which determines
|
55
|
+
- As an instance for Application 'MyEShopApp', one of Topics could be 'Authentication' and
|
56
|
+
Context could be 'uer_name' which attend in application authorization process.
|
57
|
+
- The next step is log severity level, which determines the log record severity (debug, information, warning, error, fatal, unknown)
|
60
58
|
- At last the final element is log message, which contains log message data.
|
61
59
|
|
62
60
|
### Which Log Severity Levels to use
|
@@ -96,7 +94,7 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
96
94
|
"severity_level": "debug",
|
97
95
|
"buffer_size": 100,
|
98
96
|
"flush_wait_seconds": 15,
|
99
|
-
"
|
97
|
+
"repositories":
|
100
98
|
[
|
101
99
|
{
|
102
100
|
"enable": true,
|
@@ -147,12 +145,12 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
147
145
|
```
|
148
146
|
the result will be:
|
149
147
|
```
|
150
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
151
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
152
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
153
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
154
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
155
|
-
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":
|
148
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"DEBUG","message":"user_id is nil for user: Tom"}
|
149
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"INFO","message":"User Tom is trying to login"}
|
150
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"WARN","message":"Authentication failed for user Tom"}
|
151
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"ERROR","message":"Error connecting to data base for user Tom"}
|
152
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"FATAL","message":"Authentication service has been stopped working"}
|
153
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"UNKNOWN","message":"An unknown error occured during authentication. user name: Tom"}
|
156
154
|
```
|
157
155
|
- json config file sample
|
158
156
|
```json
|
@@ -169,7 +167,7 @@ the result will be:
|
|
169
167
|
"severity_level": "debug",
|
170
168
|
"buffer_size": 100,
|
171
169
|
"flush_wait_seconds": 15,
|
172
|
-
"
|
170
|
+
"repositories":
|
173
171
|
[
|
174
172
|
{
|
175
173
|
"enable": true,
|
@@ -232,12 +230,12 @@ the result will be:
|
|
232
230
|
- enable: (true/false) The value of this property activate or deactivate entire log manager.
|
233
231
|
- app_name: Application name as the owner of log data.
|
234
232
|
- severity_level: Defines which level of log data will be stored in log repositories.
|
235
|
-
- buffer_size:
|
233
|
+
- buffer_size: Minimune possible value for this attribute is 100 and defines memory buffer size (number of buffered log objects) to
|
236
234
|
decread api consumers wait time. when the buffer is full the flush operation will
|
237
235
|
save buffered logs to log repositoies.
|
238
|
-
- flush_wait_seconds:
|
236
|
+
- flush_wait_seconds: Minimum possible value for this attribure is 10 seconds and defines time in soconds which log managers wait to flush buffered log records
|
239
237
|
to log repository.
|
240
|
-
-
|
238
|
+
- repositories: Array of log repositories. It is possible to define multiple log repositories to
|
241
239
|
store log data. there are variaty of log repositories and it is possible to
|
242
240
|
add new ones. Each item in Repos array will configure a log repository.
|
243
241
|
Pre-defined types are described below, also it's possible to implement your custome repo type
|
data/lib/RTALogger/version.rb
CHANGED
data/lib/log_formatter_json.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'jbuilder'
|
2
2
|
require_relative 'log_formatter_base'
|
3
|
+
require_relative 'severity_level'
|
3
4
|
|
4
5
|
module RTALogger
|
5
6
|
# json formatter which receive log_record and
|
6
7
|
# returns it's data as json string
|
7
8
|
class LogFormatterJson < LogFormatterBase
|
9
|
+
include SeverityLevel
|
10
|
+
|
8
11
|
def format(log_record)
|
9
12
|
return '' unless log_record
|
10
13
|
|
@@ -13,7 +16,7 @@ module RTALogger
|
|
13
16
|
json.app_name log_record.app_name
|
14
17
|
json.topic_title log_record.topic_title
|
15
18
|
json.context_id log_record.context_id
|
16
|
-
json.severity log_record.severity
|
19
|
+
json.severity parse_severity_level_to_s(log_record.severity)
|
17
20
|
json.message log_record.message.flatten.join(' ')
|
18
21
|
end
|
19
22
|
|
data/lib/log_formatter_text.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
require_relative 'log_formatter_base'
|
2
|
+
require_relative 'severity_level'
|
2
3
|
|
3
4
|
module RTALogger
|
4
5
|
# text formatter which receive log_record and
|
5
6
|
# returns it's data as delimited text string
|
6
7
|
class LogFormatterText < LogFormatterBase
|
8
|
+
include SeverityLevel
|
9
|
+
|
7
10
|
def format(log_record)
|
8
11
|
return '' unless log_record
|
9
12
|
|
10
13
|
result = log_record.occurred_at.strftime('%F %H:%M:%S:%3N')
|
11
14
|
result << @delimiter << log_record.app_name
|
12
15
|
result << @delimiter << log_record.topic_title
|
13
|
-
result << @delimiter << log_record.context_id
|
14
|
-
result << @delimiter << log_record.severity
|
16
|
+
result << @delimiter << log_record.context_id.to_s
|
17
|
+
result << @delimiter << parse_severity_level_to_s(log_record.severity)
|
15
18
|
result << @delimiter << log_record.message.join(' ').gsub(delimiter, '$<$')
|
16
19
|
|
17
20
|
result
|
data/lib/log_manager.rb
CHANGED
@@ -26,9 +26,9 @@ module RTALogger
|
|
26
26
|
@config_file_name = ''
|
27
27
|
@topic_semaphore = Mutex.new
|
28
28
|
@log_semaphore = Mutex.new
|
29
|
-
|
29
|
+
self.buffer_size = ENV.fetch('RTA_LOGGER_BUFFER_SIZE', 100)
|
30
30
|
@flush_size = @buffer_size * 20 / 100
|
31
|
-
|
31
|
+
self.flush_wait_time = ENV.fetch('RTA_LOGGER_FLUSH_WAIT_SECONDS', 15)
|
32
32
|
@topics = {}
|
33
33
|
@log_records = []
|
34
34
|
@propagator = LogFactory.new_log_propagator
|
@@ -47,12 +47,26 @@ module RTALogger
|
|
47
47
|
attr_accessor :app_name
|
48
48
|
attr_reader :propagator
|
49
49
|
attr_accessor :default_severity_level
|
50
|
-
attr_accessor :buffer_size
|
51
50
|
attr_reader :flush_size
|
52
|
-
attr_accessor :flush_wait_time
|
53
51
|
attr_reader :topics
|
54
52
|
attr_reader :config_file_name
|
55
53
|
|
54
|
+
def buffer_size
|
55
|
+
@buffer_size
|
56
|
+
end
|
57
|
+
|
58
|
+
def buffer_size=(size)
|
59
|
+
@buffer_size = size < 100 ? 100 : size
|
60
|
+
end
|
61
|
+
|
62
|
+
def flush_wait_time
|
63
|
+
@flush_wait_time
|
64
|
+
end
|
65
|
+
|
66
|
+
def flush_wait_time=(time_in_seconds)
|
67
|
+
@flush_wait_time = time_in_seconds < 10 ? 10 : time_in_seconds
|
68
|
+
end
|
69
|
+
|
56
70
|
def config_use_json_file(file_name, manager_name = '')
|
57
71
|
config_json = load_config_from_json_file(file_name, manager_name)
|
58
72
|
@config_file_name = file_name if config_json
|
@@ -162,8 +176,8 @@ module RTALogger
|
|
162
176
|
@enable = config_json['enable'].nil? ? true : config_json['enable']
|
163
177
|
@app_name = config_json['app_name'] unless config_json['app_name'].empty?
|
164
178
|
@default_severity_level = parse_severity_level_to_i(config_json['severity_level']) if config_json['severity_level']
|
165
|
-
|
166
|
-
|
179
|
+
self.buffer_size = config_json['buffer_size'] if config_json['buffer_size']
|
180
|
+
self.flush_wait_time = config_json['flush_wait_seconds'] if config_json['flush_wait_seconds']
|
167
181
|
@propagator.drop_all_repositories
|
168
182
|
apply_config_repos(config_json)
|
169
183
|
apply_config_topics(config_json)
|
@@ -187,7 +201,7 @@ module RTALogger
|
|
187
201
|
@flush_scheduler = Thread.new do
|
188
202
|
loop do
|
189
203
|
elapsed_seconds = ((DateTime.now - @last_flush_time) * 24 * 60 * 60).to_i
|
190
|
-
flush if elapsed_seconds >
|
204
|
+
flush if elapsed_seconds > flush_wait_time
|
191
205
|
sleep(1)
|
192
206
|
break if @exit_flush_scheduler
|
193
207
|
end
|
data/lib/rta_logger_config.json
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
"app_name": "TestApp",
|
11
11
|
"severity_level": "debug",
|
12
12
|
"buffer_size": 100,
|
13
|
-
"flush_wait_seconds":
|
13
|
+
"flush_wait_seconds": 10,
|
14
14
|
"repositories":
|
15
15
|
[
|
16
16
|
{
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"roll_size": "1048576",
|
31
31
|
"formatter":
|
32
32
|
{
|
33
|
-
"type": "
|
33
|
+
"type": "json",
|
34
34
|
"delimiter": "|"
|
35
35
|
}
|
36
36
|
},
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluent-logger
|