RTALogger 1.1.1 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b037c1dbb6f51228afd43cfc7e576e86a7e46e711b96cedaaeb9a5b3e5f3f1ec
4
- data.tar.gz: d1e2fb9ee4cddf0b221b0ec9c471117953387c502337e3d438b82348ce4111ae
3
+ metadata.gz: ce594204cc18c9c040fd6efa93a6390ef4ee8d8193dd2f94a5633a4dff82c33b
4
+ data.tar.gz: a5aa6fb8dcf05c391390d1766fcb536a52da3bd2e5aa381f4084da09a7e15112
5
5
  SHA512:
6
- metadata.gz: 1fe26e02fcdb17eb44f56644469f7061a925f5dfdc25afcde968b1d910eb5f25a13a49e25afeec8898e78eb7398bbcabe53fca3b7ca98dc85afdeae304ba12a0
7
- data.tar.gz: 11fdcff4f789f1eb739cd307c9f60c52b7f6a2816caa60699b0d1f607fba0a3cf7619e58dd17d6817b4711ba35f4998585e64a8d0f099142f8c3009210220759
6
+ metadata.gz: 18a50c861fbff016f990a89d39e1da24e26dd983f32ac90172818d70f7fca78cabf8c6cc26d624fd901ace2fcfa358fa49b9b0256de6dec48df867972d99757c
7
+ data.tar.gz: ba39a6640b4ac17499fcad6a7fba72db587430936c0357cfdbbec46e1a292cac28327019943687bef55cd18496fdae568742c3d4ffe11519e2a3836291a41598
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- RTALogger (1.1.1)
4
+ RTALogger (2.1.1)
5
5
  fluent-logger (~> 0.9)
6
6
  jbuilder (~> 2.10)
7
7
 
data/README.md CHANGED
@@ -58,12 +58,13 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
58
58
  - At last the final element is log message, which contains log message data.
59
59
 
60
60
  ### Which Log Severity Levels to use
61
- - DEBUG = 0 : Low-level information, mostly for developers.
62
- - INFO = 1 : Generic (useful) information about system operation.
63
- - WARN = 2 : A warning, which it does NOT cause crashing the process.
64
- - ERROR = 3 : A handleable error condition.
65
- - FATAL = 4 : An un-handleable error that results in a program crash.
66
- - UNKNOWN = 5 : An unknown message that should always be logged.
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.
67
68
 
68
69
  ### Time for coding
69
70
  - create log manager instance:
@@ -86,41 +87,76 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
86
87
  {
87
88
  "default_manager": "develop",
88
89
  "log_managers":
89
- [
90
- {
91
- "manager_name": "develop",
92
- "enable": true,
93
- "app_name": "TestApp",
94
- "severity_level": "debug",
95
- "buffer_size": 100,
96
- "flush_wait_seconds": 15,
97
- "repositories":
98
- [
99
- {
100
- "enable": true,
101
- "type": "console",
102
- "formatter": "delimited_text",
103
- "delimiter": "|"
104
- },
105
- {
106
- "enable": true,
107
- "type": "File",
108
- "file_path": "./log/log.txt",
109
- "roll_period": "daily",
110
- "roll_size": "1048576",
111
- "formatter": "delimited_text",
112
- "delimiter": "|"
113
- },
114
- {
115
- "enable": true,
116
- "type": "fluentd",
117
- "host": "localhost",
118
- "port": "8888",
119
- "formatter": "json"
120
- }
121
- ]
122
- }
123
- ]
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
+ ]
124
160
  }
125
161
  }
126
162
  ```
@@ -136,21 +172,25 @@ To use log manager APIs, first step is to have a quick review on Log Data Struct
136
172
  # Assume user 'Tom' is trying to authenticate we will use user_name as log Context_id
137
173
  user_name = 'Tom'
138
174
  topic = log_manager.add_topic('Authentication')
175
+ topic.trace(user_name, 'Authentication process began for:', user_name)
139
176
  topic.debug(user_name, 'use_id is nil for user:', user_name)
140
177
  topic.info(user_name, 'User ', user_name , ' is trying to login.')
141
178
  topic.warning(user_name, 'Authentication failed for user ', user_name)
142
179
  topic.error(user_name, 'Error connecting to data base for user ', user_name)
143
180
  topic.fatal(user_name, 'Authentication service has been stopped working')
144
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)
145
183
  ```
146
184
  the result will be:
147
185
  ```
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"}
148
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"}
149
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"}
150
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"}
151
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"}
152
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"}
153
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"}
154
194
  ```
155
195
  - json config file sample
156
196
  ```json
@@ -161,37 +201,55 @@ the result will be:
161
201
  "log_managers":
162
202
  [
163
203
  {
164
- "manager_name": "develop",
204
+ "title": "develop",
165
205
  "enable": true,
166
206
  "app_name": "TestApp",
167
- "severity_level": "debug",
207
+ "severity_level": "trace",
168
208
  "buffer_size": 100,
169
- "flush_wait_seconds": 15,
209
+ "flush_wait_seconds": 10,
170
210
  "repositories":
171
211
  [
172
212
  {
173
- "enable": true,
174
213
  "type": "console",
214
+ "title": "console_repo_1",
215
+ "enable": true,
175
216
  "formatter":
176
217
  {
177
218
  "type": "text",
178
219
  "delimiter": "|"
179
- }
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
+ ]
180
236
  },
181
237
  {
182
- "enable": false,
183
238
  "type": "file",
239
+ "title": "file_repo_1",
240
+ "enable": true,
184
241
  "file_path": "log.txt",
185
242
  "roll_period": "daily",
186
243
  "roll_size": "1048576",
187
244
  "formatter":
188
245
  {
189
- "type": "text",
246
+ "type": "json",
190
247
  "delimiter": "|"
191
248
  }
192
249
  },
193
250
  {
194
251
  "enable": false,
252
+ "title": "fluentd_repo_1",
195
253
  "type": "fluentd",
196
254
  "host": "localhost",
197
255
  "port": "8888",
@@ -206,7 +264,7 @@ the result will be:
206
264
  {
207
265
  "title": "test",
208
266
  "enable": true,
209
- "severity_level": "info"
267
+ "severity_level": "WARN"
210
268
  }
211
269
  ]
212
270
  }
@@ -214,7 +272,7 @@ the result will be:
214
272
  }
215
273
  }
216
274
  ```
217
- - json config file structure
275
+ ### json config file structure
218
276
  ```comment
219
277
  As we described you cap apply RTA log manager using a json config file.
220
278
 
@@ -226,7 +284,7 @@ the result will be:
226
284
  multiple log manager configuration in Log_Managers array.
227
285
  - log_managers : the array of LogManagers with different configuration.
228
286
  It is possible to define multiple log manager configurations for differen usages.
229
- - manager_name: the name of log manager. It will be used to define the default log manager.
287
+ - title: the name of log manager. It will be used to define the default log manager.
230
288
  - enable: (true/false) The value of this property activate or deactivate entire log manager.
231
289
  - app_name: Application name as the owner of log data.
232
290
  - severity_level: Defines which level of log data will be stored in log repositories.
@@ -274,13 +332,29 @@ the result will be:
274
332
  - "type": ["text"/"json"] type of formatter
275
333
  - "delimiter": [any text delimiter you need.(as an instance pipe line "|")]
276
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.
277
351
  - topics: This is an optional item. When you need to customize a specific topic severity level or
278
352
  enable value, you can define the settings here.
279
353
  - title: The topic title to customize. (mandatoy).
280
354
  - severity_level: Defines which level of log data will be stored in log repositories.
281
355
  - enable: [true/false] to enable or disable logging process of the topic.
282
356
  ```
283
- - Some useful features
357
+ ##Some useful features
284
358
  ```ruby
285
359
  # change log manager app name at run time
286
360
  log_manager.app_name = 'myTestApp'
@@ -296,10 +370,36 @@ the result will be:
296
370
 
297
371
  # enable or disable all topic if necessary
298
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)
299
398
  ```
300
- - Implement and Expand
399
+ ### Implement and Expand
400
+ #### Implement new customized log repository
301
401
  It is possible to implement new log repositories. There will be fue rules to implement and
302
- integrate new customized log repository with RTALogger LogManager.
402
+ integrate new customized log repository with RTALogger LogManager factory.
303
403
 
304
404
  1- Define you class inside RTALogger module.
305
405
 
@@ -307,7 +407,7 @@ the result will be:
307
407
 
308
408
  3- Also appropriate naming convention is necessary.
309
409
  As an example if you are implementing a Console Repo, your class name should be LogRepositoryConsole and
310
- 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
311
411
 
312
412
  4- After implementing your own log repository, you should register the class at run-time using the following syntax:
313
413
  ```ruby
@@ -344,17 +444,95 @@ module RTALogger
344
444
  end
345
445
  ```
346
446
 
347
- ## Development
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
348
464
 
349
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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'
350
471
 
351
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
352
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
502
+
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
519
+
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, '$<$')
526
+
527
+ result
528
+ end
529
+ end
530
+ end
531
+ ```
353
532
  ## Contributing
354
533
 
355
534
  Bug reports and pull requests are welcome on GitHub at https://github.com/BBahrainy/RTALogger.
356
535
 
357
-
358
536
  ## License
359
537
 
360
538
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module RTALogger
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '2.1.1'.freeze
3
3
  end
@@ -0,0 +1,33 @@
1
+ require_relative 'log_filter_base'
2
+
3
+ module RTALogger
4
+ # Log factory to get new instance of log filter
5
+ module LogFactory
6
+ def self.create_filter(type, config_json = '')
7
+ lib_file = @log_filters[type.to_sym]
8
+ raise "unregistered filter class: #{type.to_s}" if lib_file.nil? || lib_file.empty?
9
+ begin
10
+ load lib_file
11
+ rescue
12
+ raise "unable to load formatter class file: #{lib_file}"
13
+ end
14
+
15
+ filter_class_name = 'RTALogger::' + ('log_filter_' + type.to_s).split('_').map(&:capitalize).join
16
+ filter_class = Object.const_get(filter_class_name)
17
+ return nil unless filter_class
18
+ result = filter_class.new
19
+
20
+ return result if config_json.empty?
21
+ result.load_config(config_json) if result.present?
22
+ return result
23
+ end
24
+
25
+ def self.register_log_filter(type, class_file_name)
26
+ @log_filters[type.to_sym] = class_file_name
27
+ end
28
+
29
+ @log_filters = {:topic => 'log_filter_topic.rb',
30
+ :context => 'log_filter_context.rb',
31
+ :message => 'log_filter_message.rb'}
32
+ end
33
+ end