RTALogger 0.1.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cd821ed8beebbda5bfd6aff1088372642f5f20012c7f5d6ca8b2d59cc8dee42
4
- data.tar.gz: 8dbf6b01f03b98525acade15eaebece1e500dfbc610f2d9cbda5e760df0e048b
3
+ metadata.gz: c27d68d46d9d0ff75577b50a1b29983ce9012bc1d3dc86778b197154596ab2c5
4
+ data.tar.gz: 53ebb2215c5a2e4733de28b9178c9d4db5713aa87483309407be0de1763b36f1
5
5
  SHA512:
6
- metadata.gz: 7a1e77c33e3fb301780bb6d4a0b254701ab918403ee8705e19bda759b2c0ce56b1e1cf76c18012c195b5c3b28267dea524bbe3db303f7a9fb9dca58662fe9a2f
7
- data.tar.gz: fd81ab07bb1a3c79e00e425298068e4cfa357208e4173f157a156e5cdefcb044f456604cfc0c3b9d0f37342e672d47636ffd75ceb4b5ef866a47f8f7db9bc7aa
6
+ metadata.gz: e731b3cd50b9c13b017679a34e9136b743055e50892017a73890d5f74031f6d88fc437b8a26dee5abe8207fcc9c1616c83ab998f77ee216701c2fd0d98220cc2
7
+ data.tar.gz: 871fd3047f195f7076e08eeec631bc3f0143ea4c4f8ae483bf054e244e5e6f75541f775f0b4f973e8127a592cace225922357fb7f9167f00623f3845bd0573b7
@@ -10,10 +10,8 @@
10
10
  <orderEntry type="library" scope="PROVIDED" name="activesupport (v6.0.3.4, ruby-2.6.3-p62) [gem]" level="application" />
11
11
  <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, ruby-2.6.3-p62) [gem]" level="application" />
12
12
  <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.7, ruby-2.6.3-p62) [gem]" level="application" />
13
- <orderEntry type="library" scope="PROVIDED" name="cool.io (v1.7.0, ruby-2.6.3-p62) [gem]" level="application" />
14
13
  <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, ruby-2.6.3-p62) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="fluentd (v1.11.4, ruby-2.6.3-p62) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="http_parser.rb (v0.6.0, ruby-2.6.3-p62) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="fluent-logger (v0.9.0, ruby-2.6.3-p62) [gem]" level="application" />
17
15
  <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.5, ruby-2.6.3-p62) [gem]" level="application" />
18
16
  <orderEntry type="library" scope="PROVIDED" name="jbuilder (v2.10.1, ruby-2.6.3-p62) [gem]" level="application" />
19
17
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.2, ruby-2.6.3-p62) [gem]" level="application" />
@@ -24,13 +22,8 @@
24
22
  <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
25
23
  <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
26
24
  <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="serverengine (v2.2.2, ruby-2.6.3-p62) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="sigdump (v0.2.4, ruby-2.6.3-p62) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="strptime (v0.2.5, ruby-2.6.3-p62) [gem]" level="application" />
30
25
  <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, ruby-2.6.3-p62) [gem]" level="application" />
31
26
  <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.7, ruby-2.6.3-p62) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="tzinfo-data (v1.2020.4, ruby-2.6.3-p62) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="yajl-ruby (v1.4.1, ruby-2.6.3-p62) [gem]" level="application" />
34
27
  <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.1, ruby-2.6.3-p62) [gem]" level="application" />
35
28
  </component>
36
29
  </module>
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- RTALogger (0.1.1)
5
- fluentd (~> 1.11, >= 1.11.4)
4
+ RTALogger (1.1.0)
5
+ fluent-logger (~> 0.9)
6
6
  jbuilder (~> 2.10)
7
7
 
8
8
  GEM
@@ -15,19 +15,9 @@ GEM
15
15
  tzinfo (~> 1.1)
16
16
  zeitwerk (~> 2.2, >= 2.2.2)
17
17
  concurrent-ruby (1.1.7)
18
- cool.io (1.7.0)
19
18
  diff-lcs (1.4.4)
20
- fluentd (1.11.4)
21
- cool.io (>= 1.4.5, < 2.0.0)
22
- http_parser.rb (>= 0.5.1, < 0.7.0)
23
- msgpack (>= 1.3.1, < 2.0.0)
24
- serverengine (>= 2.0.4, < 3.0.0)
25
- sigdump (~> 0.2.2)
26
- strptime (>= 0.2.2, < 1.0.0)
27
- tzinfo (>= 1.0, < 3.0)
28
- tzinfo-data (~> 1.0)
29
- yajl-ruby (~> 1.0)
30
- http_parser.rb (0.6.0)
19
+ fluent-logger (0.9.0)
20
+ msgpack (>= 1.0.0, < 2)
31
21
  i18n (1.8.5)
32
22
  concurrent-ruby (~> 1.0)
33
23
  jbuilder (2.10.1)
@@ -48,16 +38,9 @@ GEM
48
38
  diff-lcs (>= 1.2.0, < 2.0)
49
39
  rspec-support (~> 3.10.0)
50
40
  rspec-support (3.10.0)
51
- serverengine (2.2.2)
52
- sigdump (~> 0.2.2)
53
- sigdump (0.2.4)
54
- strptime (0.2.5)
55
41
  thread_safe (0.3.6)
56
42
  tzinfo (1.2.7)
57
43
  thread_safe (~> 0.1)
58
- tzinfo-data (1.2020.4)
59
- tzinfo (>= 1.0.0)
60
- yajl-ruby (1.4.1)
61
44
  zeitwerk (2.4.1)
62
45
 
63
46
  PLATFORMS
data/README.md CHANGED
@@ -1,8 +1,32 @@
1
1
  # RTALogger
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/RTALogger`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ RTA Log Manager has been designed and implemented to provide standard logging API for developers.
4
+ This prevents chaos in log data format.
5
+ Also provide multiple extendable log repositories including wrapping existing loggers, like 'Fluentd' or implement completely new custom logger.
6
+ All log manager's main features are configable through a json config file.
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+ Main purposes of developing this gem are:
9
+ - Creating standard logging API to seperate application from existing variety of loggers.
10
+ - Wrapping around existing loggers so get advantage of different loggers at the same time.
11
+ - Make it possible to easily replace a logger component with a new one. (for example Rails standard Logger with Fluentd)
12
+ without any changes in the consumer application.
13
+ - Creating easy to use logger interface.
14
+ - Apply some rules and restrictions about log structure and data format, which prevents chaos in application log information.
15
+ - No interrupt or wait time for log consumer modules.
16
+ - Utilize multiple log repositories at the same time in background (Console, File, UDP, FluentD, etc.)
17
+ - Make it possible to implement customized log repositories.
18
+
19
+ Main Features:
20
+ - Creating multiple log manager instances with different configuration is possible entire application.
21
+ - Each log manager instance could be configured via a json file.
22
+ - Each log manager instance could be config to use multiple log repositories such as Console, File, UDP, Fluentd.
23
+ - Runtime configurations could be applied through log manager APIs.
24
+ - By using multi threading techniques and also buffering techniques,
25
+ all logging process will handled in seperated thread.
26
+ So the log consumer modules should not be wait for log manager to finish the logging task.
27
+ - Multiple standard log severity levels are available through topic APIs (debug, info, warning, error, fatal, unknown)
28
+ - Main features could be set and manipulate through json configuration file.
29
+ - And at the end, it is easy to use for ruby backend developers.
6
30
 
7
31
  ## Installation
8
32
 
@@ -20,45 +44,307 @@ Or install it yourself as:
20
44
 
21
45
  $ gem install RTALogger
22
46
 
47
+ To add gem to your rails application:
48
+
49
+ $ bundle add RTALogger
50
+
23
51
  ## Usage
52
+ #### RTA Log Data Structure
53
+ 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.
55
+ - Topic: By adding multiple topics to log manager you can categorize log data in logical topics.
56
+ - Context: Under each topic, one or multiple contexts (in one level) could be defined.
57
+ - As an instance the Application could by 'MyEShopApp', one of Topics could be 'Authentication' and
58
+ Contexts could be 'uer_name' which attend in application authorization process.
59
+ - The next step is log severity level, which determines that the log record severity (debug, information, warning, error, fatal, unknown)
60
+ - At last the final element is log message, which contains log message data.
24
61
 
25
- require_relative 'log_factory_manager'
26
- require_relative 'log_factory_repository'
62
+ ### Which Log Severity Levels to use
63
+ - DEBUG = 0 : Low-level information, mostly for developers.
64
+ - INFO = 1 : Generic (useful) information about system operation.
65
+ - WARN = 2 : A warning, which it does NOT cause crashing the process.
66
+ - ERROR = 3 : A handleable error condition.
67
+ - FATAL = 4 : An un-handleable error that results in a program crash.
68
+ - UNKNOWN = 5 : An unknown message that should always be logged.
69
+
70
+ ### Time for coding
71
+ - create log manager instance:
72
+ ```ruby
73
+ # add required files
74
+ require 'log_factory_manager'
27
75
 
28
- controller_name = 'test_controller'
29
- userID = 5
76
+ # create log manager instance using LogFactory
77
+ log_manager = RTALogger::LogFactory.log_manager_instance
78
+ ```
79
+ - Apply configuration using json config file
80
+ ```ruby
81
+ # the parameter is the json config file
82
+ log_manager.config_use_json_file('rta_logger_config.json')
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
+ ```
129
+ - Add new topic to log manager and get the topic instance
130
+ ```ruby
131
+ # the parameter is the topic name
132
+ # if add_topic API called multiple times with same parameter,
133
+ # only one instance will be created for that topic
134
+ topic = log_manager.add_topic('Authentication')
135
+ ```
136
+ - Finally add log message using topic instance
137
+ ```ruby
138
+ # Assume user 'Tom' is trying to authenticate we will use user_name as log Context_id
139
+ user_name = 'Tom'
140
+ topic = log_manager.add_topic('Authentication')
141
+ topic.debug(user_name, 'use_id is nil for user:', user_name)
142
+ topic.info(user_name, 'User ', user_name , ' is trying to login.')
143
+ topic.warning(user_name, 'Authentication failed for user ', user_name)
144
+ topic.error(user_name, 'Error connecting to data base for user ', user_name)
145
+ topic.fatal(user_name, 'Authentication service has been stopped working')
146
+ topic.unknown(user_name, 'An unknown error occured during authentication. user name:', user_name)
147
+ ```
148
+ the result will be:
149
+ ```
150
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":0,"message":"user_id is nil for user: Tom"}
151
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":1,"message":"User Tom is trying to login"}
152
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":2,"message":"Authentication failed for user Tom"}
153
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":3,"message":"Error connecting to data base for user Tom"}
154
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":4,"message":"Authentication service has been stopped working"}
155
+ {"occurred_at":"2020-11-04 15:56:58:785","app_name":"TestApp","topic_title":"Authentication","context_id":"Tom","severity":5,"message":"An unknown error occured during authentication. user name: Tom"}
156
+ ```
157
+ - json config file sample
158
+ ```json
159
+ {
160
+ "rta_logger":
161
+ {
162
+ "default_manager": "develop",
163
+ "log_managers":
164
+ [
165
+ {
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":
173
+ [
174
+ {
175
+ "enable": true,
176
+ "type": "console",
177
+ "formatter":
178
+ {
179
+ "type": "text",
180
+ "delimiter": "|"
181
+ }
182
+ },
183
+ {
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
+ }
194
+ },
195
+ {
196
+ "enable": false,
197
+ "type": "fluentd",
198
+ "host": "localhost",
199
+ "port": "8888",
200
+ "formatter":
201
+ {
202
+ "type": "json"
203
+ }
204
+ }
205
+ ],
206
+ "topics":
207
+ [
208
+ {
209
+ "title": "test",
210
+ "enable": true,
211
+ "severity_level": "info"
212
+ }
213
+ ]
214
+ }
215
+ ]
216
+ }
217
+ }
218
+ ```
219
+ - json config file structure
220
+ ```comment
221
+ As we described you cap apply RTA log manager using a json config file.
222
+
223
+ log_manager.config_use_json_file('rta_logger_config.json')
224
+
225
+ The file structure:
226
+ - rta_logger : the root element of rta_logger json configuration.
227
+ - default_manager: the name of default log manager config, when there is
228
+ multiple log manager configuration in Log_Managers array.
229
+ - log_managers : the array of LogManagers with different configuration.
230
+ It is possible to define multiple log manager configurations for differen usages.
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
236
+ decread api consumers wait time. when the buffer is full the flush operation will
237
+ save buffered logs to log repositoies.
238
+ - flush_wait_seconds: Time in soconds which log managers wait to flush buffered log objects
239
+ to log repository.
240
+ - repos: Array of log repositories. It is possible to define multiple log repositories to
241
+ store log data. there are variaty of log repositories and it is possible to
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.
245
+ - Log repository types and config:
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
259
+ roll file and create the new log file
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.
284
+ ```
285
+ - Some useful features
286
+ ```ruby
287
+ # change log manager app name at run time
288
+ log_manager.app_name = 'myTestApp'
30
289
 
31
- # create log manager instance
32
- # this could be a global variable declared in application level
33
- log_manager = RTALogger::LogFactory.log_manager_instance
290
+ # update specific topic log level if necessary
291
+ log_manager.update_topic_severity_level(topic_title, RTALogger::SeverityLevel::INFO)
34
292
 
35
- # set log manage application name (hard code)
36
- log_manager.app_name = 'myTestApp'
293
+ # update all topics severity level if necessary
294
+ log_manager.update_all_topics_severity_level(RTALogger::SeverityLevel::INFO)
37
295
 
38
- # load log manager configuration from a json config file
39
- log_manager.config_use_json_file('rta_logger_config.json')
296
+ # enable or disable specific topic if necessary
297
+ log_manager.update_topic_enable(topic_title, [true/false])
40
298
 
41
- # add log repository to log manager
42
- #log_manager.propagator.add_log_repository(RTALogger::LogFactory.new_log_repository_console)
299
+ # enable or disable all topic if necessary
300
+ log_manager.update_all_topics_enable([true/false])
301
+ ```
302
+ - Implement and Expand
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
+ ```
323
+ Here is 'LogRepositoryConsole' implementation:
324
+ ```ruby
325
+ require_relative 'log_repository'
326
+ require_relative 'log_factory_log_formatter'
43
327
 
44
- # add new topic to log manager
45
- # use this api to get a new log topic instance
46
- # this api could be called in entry point of each service or class initialize method
47
- topic = log_manager.add_topic(controller_name)
328
+ module RTALogger
329
+ # show log items on console out put
330
+ class LogRepositoryConsole < LogRepository
331
+ def initialize
332
+ super
48
333
 
49
- # add log information to log topic
50
- topic.debug(userID, 'Controller Name=', controller_name, 'debug')
51
- topic.info(userID, 'Controller Name=', controller_name, 'information')
52
- topic.warning(userID, 'Controller Name=', controller_name, 'warning')
53
- topic.error(userID, 'Controller Name=', controller_name, 'error')
54
- topic.fatal(userID, 'Controller Name=', controller_name, 'fatal')
55
- topic.unknown(userID, 'Controller Name=', controller_name, 'unknown')
334
+ @formatter = RTALogger::LogFactory.log_formatter_default
335
+ end
56
336
 
57
- # update specific topic log level if necessary
58
- # log_manager.update_topic_level(controller_name, RTALogger::LogSeverity::INFO)
337
+ protected
59
338
 
60
- # update all topics log level if necessary
61
- # log_manager.update_all_topics_log_level(RTALogger::LogSeverity::INFO)
339
+ def flush_and_clear
340
+ semaphore.synchronize do
341
+ @log_records.each { |log_record| puts @formatter.format(log_record) }
342
+ end
343
+ super
344
+ end
345
+ end
346
+ end
347
+ ```
62
348
 
63
349
  ## Development
64
350
 
@@ -68,7 +354,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
68
354
 
69
355
  ## Contributing
70
356
 
71
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/RTALogger.
357
+ Bug reports and pull requests are welcome on GitHub at https://github.com/BBahrainy/RTALogger.
72
358
 
73
359
 
74
360
  ## License