RTALogger 0.1.0 → 1.0.0
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/.idea/.gitignore +2 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/RTALogger.iml +29 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +21 -23
- data/README.md +326 -4
- data/RTALogger.gemspec +2 -1
- data/lib/RTALogger.rb +2 -4
- data/lib/RTALogger/version.rb +1 -1
- data/lib/log_factory_log_formatter.rb +35 -0
- data/lib/{factory/origin/log_factory_manager.rb → log_factory_manager.rb} +1 -3
- data/lib/{factory/origin/log_factory_propagator.rb → log_factory_propagator.rb} +1 -2
- data/lib/{factory/origin/log_factory_record.rb → log_factory_record.rb} +1 -1
- data/lib/log_factory_repository.rb +37 -0
- data/lib/log_factory_topic.rb +12 -0
- data/lib/log_formatter.rb +11 -1
- data/lib/log_formatter_json.rb +4 -2
- data/lib/log_formatter_text.rb +8 -6
- data/lib/log_manager.rb +126 -40
- data/lib/log_propagator.rb +44 -45
- data/lib/log_record.rb +27 -28
- data/lib/log_repository.rb +26 -4
- data/lib/log_repository_console.rb +8 -3
- data/lib/log_repository_file.rb +24 -6
- data/lib/log_repository_fluent.rb +49 -0
- data/lib/log_repository_udp.rb +14 -7
- data/lib/log_topic.rb +26 -18
- data/lib/rta_logger_config.json +59 -0
- data/lib/sample.rb +48 -0
- data/lib/severity_level.rb +60 -0
- metadata +34 -20
- data/lib/factory/origin/log_factory_file_logger.rb +0 -16
- data/lib/factory/origin/log_factory_log_formatter.rb +0 -11
- data/lib/factory/origin/log_factory_repository.rb +0 -44
- data/lib/factory/origin/log_factory_topic.rb +0 -12
- data/lib/log_severity.rb +0 -17
- data/lib/log_test.rb +0 -41
- data/lib/log_test_db.rb +0 -59
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/.idea/.gitignore
ADDED
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build RTALogger-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install RTALogger-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install RTALogger-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push RTALogger-0.1.0.gem to https://www.rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /></RakeGroup></Settings>
|
data/.idea/RTALogger.iml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$" />
|
8
|
+
<orderEntry type="inheritedJdk" />
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.0.3.4, ruby-2.6.3-p62) [gem]" level="application" />
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, ruby-2.6.3-p62) [gem]" level="application" />
|
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="diff-lcs (v1.4.4, 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" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.5, ruby-2.6.3-p62) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="jbuilder (v2.10.1, ruby-2.6.3-p62) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.2, ruby-2.6.3-p62) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="msgpack (v1.3.3, ruby-2.6.3-p62) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, ruby-2.6.3-p62) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.0, ruby-2.6.3-p62) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, ruby-2.6.3-p62) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.7, ruby-2.6.3-p62) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.1, ruby-2.6.3-p62) [gem]" level="application" />
|
28
|
+
</component>
|
29
|
+
</module>
|
data/.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="JavaScriptSettings">
|
4
|
+
<option name="languageLevel" value="ES6" />
|
5
|
+
</component>
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.3-p62" project-jdk-type="RUBY_SDK" />
|
7
|
+
</project>
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/RTALogger.iml" filepath="$PROJECT_DIR$/.idea/RTALogger.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
RTALogger (
|
5
|
-
|
4
|
+
RTALogger (1.0.0)
|
5
|
+
fluent-logger (~> 0.9)
|
6
|
+
jbuilder (~> 2.10)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
activesupport (6.0.3.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
10
17
|
concurrent-ruby (1.1.7)
|
11
|
-
cool.io (1.7.0)
|
12
18
|
diff-lcs (1.4.4)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
tzinfo (>= 1.0, < 3.0)
|
21
|
-
tzinfo-data (~> 1.0)
|
22
|
-
yajl-ruby (~> 1.0)
|
23
|
-
http_parser.rb (0.6.0)
|
19
|
+
fluent-logger (0.9.0)
|
20
|
+
msgpack (>= 1.0.0, < 2)
|
21
|
+
i18n (1.8.5)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
jbuilder (2.10.1)
|
24
|
+
activesupport (>= 5.0.0)
|
25
|
+
minitest (5.14.2)
|
24
26
|
msgpack (1.3.3)
|
25
27
|
rake (12.3.3)
|
26
28
|
rspec (3.10.0)
|
@@ -36,21 +38,17 @@ GEM
|
|
36
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
39
|
rspec-support (~> 3.10.0)
|
38
40
|
rspec-support (3.10.0)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
tzinfo (2.0.2)
|
44
|
-
concurrent-ruby (~> 1.0)
|
45
|
-
tzinfo-data (1.2020.4)
|
46
|
-
tzinfo (>= 1.0.0)
|
47
|
-
yajl-ruby (1.4.1)
|
41
|
+
thread_safe (0.3.6)
|
42
|
+
tzinfo (1.2.7)
|
43
|
+
thread_safe (~> 0.1)
|
44
|
+
zeitwerk (2.4.1)
|
48
45
|
|
49
46
|
PLATFORMS
|
50
47
|
ruby
|
51
48
|
|
52
49
|
DEPENDENCIES
|
53
50
|
RTALogger!
|
51
|
+
jbuilder
|
54
52
|
rake (~> 12.0)
|
55
53
|
rspec (~> 3.0)
|
56
54
|
|
data/README.md
CHANGED
@@ -1,8 +1,32 @@
|
|
1
1
|
# RTALogger
|
2
2
|
|
3
|
-
|
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
|
-
|
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,9 +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.
|
61
|
+
|
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'
|
75
|
+
|
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'
|
289
|
+
|
290
|
+
# update specific topic log level if necessary
|
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)
|
295
|
+
|
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])
|
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'
|
327
|
+
|
328
|
+
module RTALogger
|
329
|
+
# show log items on console out put
|
330
|
+
class LogRepositoryConsole < LogRepository
|
331
|
+
def initialize
|
332
|
+
super
|
24
333
|
|
25
|
-
|
334
|
+
@formatter = RTALogger::LogFactory.log_formatter_default
|
335
|
+
end
|
336
|
+
|
337
|
+
protected
|
338
|
+
|
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
|
+
```
|
26
348
|
|
27
349
|
## Development
|
28
350
|
|
@@ -32,7 +354,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
354
|
|
33
355
|
## Contributing
|
34
356
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
357
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/BBahrainy/RTALogger.
|
36
358
|
|
37
359
|
|
38
360
|
## License
|