RTALogger 1.1.0 → 2.1.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 +261 -85
- data/lib/RTALogger/version.rb +1 -1
- data/lib/log_factory_filter.rb +33 -0
- data/lib/log_filter_base.rb +39 -0
- data/lib/log_filter_context.rb +13 -0
- data/lib/log_filter_message.rb +13 -0
- data/lib/log_filter_topic.rb +13 -0
- data/lib/log_formatter_json.rb +4 -1
- data/lib/log_formatter_text.rb +5 -2
- data/lib/log_manager.rb +72 -32
- data/lib/log_propagator.rb +62 -6
- data/lib/log_record.rb +4 -0
- data/lib/log_repository.rb +65 -2
- data/lib/log_repository_console.rb +1 -1
- data/lib/log_repository_file.rb +6 -1
- data/lib/log_repository_fluentd.rb +51 -8
- data/lib/log_topic.rb +11 -0
- data/lib/rta_logger_config.json +26 -8
- data/lib/sample.rb +2 -1
- data/lib/severity_level.rb +39 -31
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31a37c1f8f9ce88c8fae11d7df9fe88d397e9e21da9c8b13ddce48fe5e216c5
|
4
|
+
data.tar.gz: 920e2000e9cf216dea8251dd6e6b5b2e3e2c114533e7459cd698eb2131c69c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 626deeb001694ef40e87743bb61742f1db0cbeeb46125f1f7b3185a52d33494d811439c3bc9d669c15e60563c9dc71d305159d3c801c06cdfcce82c4450970d0
|
7
|
+
data.tar.gz: 2a3a39efce340c0e0e204ebf6390d17283f6804b3846b3b086e849c25d92e9aec9994beb2a06ab6c81cf10a9abc8af0ded19d37317adbbe5abe16c1744a43aff
|
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,21 +49,22 @@ 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
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
61
|
+
- TRACE = 0 : all information that helps us to trace the processing of an incoming request through our application.
|
62
|
+
- DEBUG = 1 : Low-level information, mostly for developers.
|
63
|
+
- INFO = 2 : Generic (useful) information about system operation.
|
64
|
+
- WARN = 3 : A warning, which it does NOT cause crashing the process.
|
65
|
+
- ERROR = 4 : A handleable error condition.
|
66
|
+
- FATAL = 5 : An un-handleable error that results in a program crash.
|
67
|
+
- UNKNOWN = 6 : An unknown message that should always be logged.
|
69
68
|
|
70
69
|
### Time for coding
|
71
70
|
- create log manager instance:
|
@@ -88,41 +87,76 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
88
87
|
{
|
89
88
|
"default_manager": "develop",
|
90
89
|
"log_managers":
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
90
|
+
[
|
91
|
+
{
|
92
|
+
"title": "develop",
|
93
|
+
"enable": true,
|
94
|
+
"app_name": "TestApp",
|
95
|
+
"severity_level": "trace",
|
96
|
+
"buffer_size": 100,
|
97
|
+
"flush_wait_seconds": 10,
|
98
|
+
"repositories":
|
99
|
+
[
|
100
|
+
{
|
101
|
+
"type": "console",
|
102
|
+
"title": "console_repo_1",
|
103
|
+
"enable": true,
|
104
|
+
"formatter":
|
105
|
+
{
|
106
|
+
"type": "text",
|
107
|
+
"delimiter": "|"
|
108
|
+
},
|
109
|
+
"filters":
|
110
|
+
[
|
111
|
+
{
|
112
|
+
"type": "topic",
|
113
|
+
"title": "topic_filter_1",
|
114
|
+
"enable": true,
|
115
|
+
"default_regex" : "^test$"
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"type": "message",
|
119
|
+
"title": "message_filter_1",
|
120
|
+
"enable": false,
|
121
|
+
"default_regex" : "error"
|
122
|
+
}
|
123
|
+
]
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"type": "file",
|
127
|
+
"title": "file_repo_1",
|
128
|
+
"enable": true,
|
129
|
+
"file_path": "log.txt",
|
130
|
+
"roll_period": "daily",
|
131
|
+
"roll_size": "1048576",
|
132
|
+
"formatter":
|
133
|
+
{
|
134
|
+
"type": "json",
|
135
|
+
"delimiter": "|"
|
136
|
+
}
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"enable": false,
|
140
|
+
"title": "fluentd_repo_1",
|
141
|
+
"type": "fluentd",
|
142
|
+
"host": "localhost",
|
143
|
+
"port": "8888",
|
144
|
+
"formatter":
|
145
|
+
{
|
146
|
+
"type": "json"
|
147
|
+
}
|
148
|
+
}
|
149
|
+
],
|
150
|
+
"topics":
|
151
|
+
[
|
152
|
+
{
|
153
|
+
"title": "test",
|
154
|
+
"enable": true,
|
155
|
+
"severity_level": "WARN"
|
156
|
+
}
|
157
|
+
]
|
158
|
+
}
|
159
|
+
]
|
126
160
|
}
|
127
161
|
}
|
128
162
|
```
|
@@ -138,21 +172,25 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
|
|
138
172
|
# Assume user 'Tom' is trying to authenticate we will use user_name as log Context_id
|
139
173
|
user_name = 'Tom'
|
140
174
|
topic = log_manager.add_topic('Authentication')
|
175
|
+
topic.trace(user_name, 'Authentication process began for:', user_name)
|
141
176
|
topic.debug(user_name, 'use_id is nil for user:', user_name)
|
142
177
|
topic.info(user_name, 'User ', user_name , ' is trying to login.')
|
143
178
|
topic.warning(user_name, 'Authentication failed for user ', user_name)
|
144
179
|
topic.error(user_name, 'Error connecting to data base for user ', user_name)
|
145
180
|
topic.fatal(user_name, 'Authentication service has been stopped working')
|
146
181
|
topic.unknown(user_name, 'An unknown error occured during authentication. user name:', user_name)
|
182
|
+
topic.trace(user_name, 'Authentication process end for:', user_name)
|
147
183
|
```
|
148
184
|
the result will be:
|
149
185
|
```
|
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":
|
186
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"TRACE","message"Authentication process began for: Tom"}
|
187
|
+
{"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"}
|
188
|
+
{"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"}
|
189
|
+
{"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"}
|
190
|
+
{"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"}
|
191
|
+
{"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"}
|
192
|
+
{"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"}
|
193
|
+
{"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":"TRACE","message"Authentication process end for: Tom"}
|
156
194
|
```
|
157
195
|
- json config file sample
|
158
196
|
```json
|
@@ -163,37 +201,55 @@ the result will be:
|
|
163
201
|
"log_managers":
|
164
202
|
[
|
165
203
|
{
|
166
|
-
"
|
204
|
+
"title": "develop",
|
167
205
|
"enable": true,
|
168
206
|
"app_name": "TestApp",
|
169
|
-
"severity_level": "
|
207
|
+
"severity_level": "trace",
|
170
208
|
"buffer_size": 100,
|
171
|
-
"flush_wait_seconds":
|
172
|
-
"
|
209
|
+
"flush_wait_seconds": 10,
|
210
|
+
"repositories":
|
173
211
|
[
|
174
212
|
{
|
175
|
-
"enable": true,
|
176
213
|
"type": "console",
|
214
|
+
"title": "console_repo_1",
|
215
|
+
"enable": true,
|
177
216
|
"formatter":
|
178
217
|
{
|
179
218
|
"type": "text",
|
180
219
|
"delimiter": "|"
|
181
|
-
}
|
220
|
+
},
|
221
|
+
"filters":
|
222
|
+
[
|
223
|
+
{
|
224
|
+
"type": "topic",
|
225
|
+
"title": "topic_filter_1",
|
226
|
+
"enable": true,
|
227
|
+
"default_regex" : "^test$"
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"type": "message",
|
231
|
+
"title": "message_filter_1",
|
232
|
+
"enable": false,
|
233
|
+
"default_regex" : "error"
|
234
|
+
}
|
235
|
+
]
|
182
236
|
},
|
183
237
|
{
|
184
|
-
"enable": false,
|
185
238
|
"type": "file",
|
239
|
+
"title": "file_repo_1",
|
240
|
+
"enable": true,
|
186
241
|
"file_path": "log.txt",
|
187
242
|
"roll_period": "daily",
|
188
243
|
"roll_size": "1048576",
|
189
244
|
"formatter":
|
190
245
|
{
|
191
|
-
"type": "
|
246
|
+
"type": "json",
|
192
247
|
"delimiter": "|"
|
193
248
|
}
|
194
249
|
},
|
195
250
|
{
|
196
251
|
"enable": false,
|
252
|
+
"title": "fluentd_repo_1",
|
197
253
|
"type": "fluentd",
|
198
254
|
"host": "localhost",
|
199
255
|
"port": "8888",
|
@@ -208,7 +264,7 @@ the result will be:
|
|
208
264
|
{
|
209
265
|
"title": "test",
|
210
266
|
"enable": true,
|
211
|
-
"severity_level": "
|
267
|
+
"severity_level": "WARN"
|
212
268
|
}
|
213
269
|
]
|
214
270
|
}
|
@@ -216,7 +272,7 @@ the result will be:
|
|
216
272
|
}
|
217
273
|
}
|
218
274
|
```
|
219
|
-
|
275
|
+
### json config file structure
|
220
276
|
```comment
|
221
277
|
As we described you cap apply RTA log manager using a json config file.
|
222
278
|
|
@@ -228,16 +284,16 @@ the result will be:
|
|
228
284
|
multiple log manager configuration in Log_Managers array.
|
229
285
|
- log_managers : the array of LogManagers with different configuration.
|
230
286
|
It is possible to define multiple log manager configurations for differen usages.
|
231
|
-
-
|
287
|
+
- title: the name of log manager. It will be used to define the default log manager.
|
232
288
|
- enable: (true/false) The value of this property activate or deactivate entire log manager.
|
233
289
|
- app_name: Application name as the owner of log data.
|
234
290
|
- severity_level: Defines which level of log data will be stored in log repositories.
|
235
|
-
- buffer_size:
|
291
|
+
- buffer_size: Minimune possible value for this attribute is 100 and defines memory buffer size (number of buffered log objects) to
|
236
292
|
decread api consumers wait time. when the buffer is full the flush operation will
|
237
293
|
save buffered logs to log repositoies.
|
238
|
-
- flush_wait_seconds:
|
294
|
+
- 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
295
|
to log repository.
|
240
|
-
-
|
296
|
+
- repositories: Array of log repositories. It is possible to define multiple log repositories to
|
241
297
|
store log data. there are variaty of log repositories and it is possible to
|
242
298
|
add new ones. Each item in Repos array will configure a log repository.
|
243
299
|
Pre-defined types are described below, also it's possible to implement your custome repo type
|
@@ -276,13 +332,29 @@ the result will be:
|
|
276
332
|
- "type": ["text"/"json"] type of formatter
|
277
333
|
- "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
|
278
334
|
if formatter not defined then the json formatter will be used
|
335
|
+
New Features:
|
336
|
+
* In RTALogger version 2.1.0 and above defineing filters is possible for each repository.
|
337
|
+
* Repositories filtes could restrict the amount of data stored by specific repository.
|
338
|
+
* Also you can add new repositories and filters at run time.
|
339
|
+
* filters configuration: It's possible to apply multiple filters on a repository. When repository will
|
340
|
+
flush a log_record only if the record pass all filter conditions.
|
341
|
+
* There are variaty of filter types, including:
|
342
|
+
'topic' which apply a regular expresion on log_record.topic_title to pass filtering condition.
|
343
|
+
'context' which apply a regular expresion on log_record.context_id to pass filtering condition.
|
344
|
+
'message' which apply a regular expression on log_record.full_message to pass filtering condition.
|
345
|
+
* Each filter has following attributes to counfigure:
|
346
|
+
"type": ["topic"/"context"/"message" or any customized filter] described in previous lines.
|
347
|
+
"title": "filte_title" a unique title to make filter run time configuration
|
348
|
+
"enable": [true/false] this will enable or disable filtering opration of current filter.
|
349
|
+
"default_regex": "valid regual expression" to compare with corresponding attribute.
|
350
|
+
* It's possible to implement customize filter classes and integerate with RTALogger filter factory.
|
279
351
|
- topics: This is an optional item. When you need to customize a specific topic severity level or
|
280
352
|
enable value, you can define the settings here.
|
281
353
|
- title: The topic title to customize. (mandatoy).
|
282
354
|
- severity_level: Defines which level of log data will be stored in log repositories.
|
283
355
|
- enable: [true/false] to enable or disable logging process of the topic.
|
284
356
|
```
|
285
|
-
|
357
|
+
###Some useful features
|
286
358
|
```ruby
|
287
359
|
# change log manager app name at run time
|
288
360
|
log_manager.app_name = 'myTestApp'
|
@@ -298,10 +370,36 @@ the result will be:
|
|
298
370
|
|
299
371
|
# enable or disable all topic if necessary
|
300
372
|
log_manager.update_all_topics_enable([true/false])
|
373
|
+
|
374
|
+
# to get log manager configuration as json object use to_builder method
|
375
|
+
log_manager.to_builder
|
376
|
+
|
377
|
+
# to get log manager configuration as json string use reveal_config method
|
378
|
+
log_manager.reveal_config
|
379
|
+
|
380
|
+
# to apply some limited changes on log manager functionality at run time
|
381
|
+
# config_json parameter should carry a json object which contains the configuration
|
382
|
+
# structure described before in 'json configuration file structure' section.
|
383
|
+
# Attention: these changes will apply to manager but will not save.
|
384
|
+
# So during next load these changes will be lost. Save changes will be available in
|
385
|
+
# next version.
|
386
|
+
# Attention: only following attributes could be change at run time:
|
387
|
+
# log_manager.enable
|
388
|
+
# log_manager.default_severity_level
|
389
|
+
# log_manager.buffer_size (minimum is 100)
|
390
|
+
# log_manager.flush_wait_time (minimum 15 second)
|
391
|
+
# repository.enable
|
392
|
+
# topic.enable
|
393
|
+
# topic.severity_level
|
394
|
+
# Other attributes could only change via config file via manager config_use_json_file
|
395
|
+
# In RTALogger version 2.1.0 and above, it is possible to add new repositories or repository filters at run time
|
396
|
+
# using log_manager.apply_run_time_config method.
|
397
|
+
log_manager.apply_run_time_config(config_json)
|
301
398
|
```
|
302
|
-
|
399
|
+
### Implement and Expand
|
400
|
+
#### Implement new customized log repository
|
303
401
|
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.
|
402
|
+
integrate new customized log repository with RTALogger LogManager factory.
|
305
403
|
|
306
404
|
1- Define you class inside RTALogger module.
|
307
405
|
|
@@ -309,7 +407,7 @@ the result will be:
|
|
309
407
|
|
310
408
|
3- Also appropriate naming convention is necessary.
|
311
409
|
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
|
410
|
+
your source code should be placed in a ruby file and name it log_repository_console.rb
|
313
411
|
|
314
412
|
4- After implementing your own log repository, you should register the class at run-time using the following syntax:
|
315
413
|
```ruby
|
@@ -346,17 +444,95 @@ module RTALogger
|
|
346
444
|
end
|
347
445
|
```
|
348
446
|
|
349
|
-
|
447
|
+
#### Implement new customized log repository filter
|
448
|
+
It is possible to implement new log repository filter. There will be fue rules to implement and
|
449
|
+
integrate new customized log repository filter with RTALogger LogManager factory.
|
450
|
+
|
451
|
+
1- Define you class inside RTALogger module.
|
452
|
+
|
453
|
+
2- The class should be inherited from 'RTALogger::LogFilterBase'.
|
454
|
+
|
455
|
+
3- Also appropriate naming convention is necessary.
|
456
|
+
As an example if you are implementing a Console Repo, your class name should be LogFilterTopic and
|
457
|
+
your source code should be placed in a ruby file and name it log_filter_topic.rb
|
458
|
+
|
459
|
+
4- After implementing your own log filter, you should register the class at run-time using the following syntax:
|
460
|
+
```ruby
|
461
|
+
RTALogger::LogFactory.register_log_filter :topic, 'log_filter_topic.rb'
|
462
|
+
```
|
463
|
+
Another example: LogFilterMyCustomizedFilter
|
464
|
+
|
465
|
+
```ruby
|
466
|
+
RTALogger::LogFactory.register_log_filter :my_customized_filter, 'log_repository_my_customized_filter.rb'
|
467
|
+
```
|
468
|
+
Here is 'LogRepositoryTopic' implementation:
|
469
|
+
```ruby
|
470
|
+
require_relative 'log_filter_base'
|
471
|
+
|
472
|
+
module RTALogger
|
473
|
+
class LogFilterTopic < LogFilterBase
|
474
|
+
def match_conditions(log_record)
|
475
|
+
return true if !@enable
|
476
|
+
result = super
|
477
|
+
return result unless result
|
478
|
+
|
479
|
+
return default_regex.present? ? (Regexp.new(@default_regex).match(log_record.topic_title)) : result
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
```
|
484
|
+
#### Implement new customized log formatter
|
485
|
+
|
486
|
+
It is possible to implement new log formatter. There will be fue rules to implement and
|
487
|
+
integrate new customized log formatter with RTALogger LogManager factory.
|
488
|
+
|
489
|
+
1- Define you class inside RTALogger module.
|
490
|
+
|
491
|
+
2- The class should be inherited from 'RTALogger::LogFormatter'.
|
492
|
+
|
493
|
+
3- Also appropriate naming convention is necessary.
|
494
|
+
As an example if you are implementing a Text formatter, your class name should be LogFormatterText and
|
495
|
+
your source code should be placed in a ruby file and name it log_formatter_text.rb
|
496
|
+
|
497
|
+
4- After implementing your own log formatter, you should register the class at run-time using the following syntax:
|
498
|
+
```ruby
|
499
|
+
RTALogger::LogFactory.register_log_formatter :text, 'log_formatter_text.rb'
|
500
|
+
```
|
501
|
+
Another example: LogFormatterMyCustomizedFormatter
|
350
502
|
|
351
|
-
|
503
|
+
```ruby
|
504
|
+
RTALogger::LogFactory.register_log_formatter :my_customized_formatter, 'log_formatter_my_customized_formatter.rb'
|
505
|
+
```
|
506
|
+
Here is 'LogFormatterText' implementation:
|
507
|
+
```ruby
|
508
|
+
require_relative 'log_formatter_base'
|
509
|
+
require_relative 'severity_level'
|
510
|
+
|
511
|
+
module RTALogger
|
512
|
+
# text formatter which receive log_record and
|
513
|
+
# returns it's data as delimited text string
|
514
|
+
class LogFormatterText < LogFormatterBase
|
515
|
+
include SeverityLevel
|
516
|
+
|
517
|
+
def format(log_record)
|
518
|
+
return '' unless log_record
|
352
519
|
|
353
|
-
|
520
|
+
result = log_record.occurred_at.strftime('%F %H:%M:%S:%3N')
|
521
|
+
result << @delimiter << log_record.app_name
|
522
|
+
result << @delimiter << log_record.topic_title
|
523
|
+
result << @delimiter << log_record.context_id.to_s
|
524
|
+
result << @delimiter << parse_severity_level_to_s(log_record.severity)
|
525
|
+
result << @delimiter << log_record.message.join(' ').gsub(delimiter, '$<$')
|
354
526
|
|
527
|
+
result
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
```
|
355
532
|
## Contributing
|
356
533
|
|
357
534
|
Bug reports and pull requests are welcome on GitHub at https://github.com/BBahrainy/RTALogger.
|
358
535
|
|
359
|
-
|
360
536
|
## License
|
361
537
|
|
362
538
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|