libis-tools 0.9.21 → 0.9.22
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/lib/libis/tools/config.rb +5 -3
- data/lib/libis/tools/logger.rb +9 -0
- data/lib/libis/tools/version.rb +1 -1
- data/libis-tools.gemspec +1 -1
- data/spec/logger_spec.rb +143 -68
- metadata +4 -5
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fa0a518d621cbae23b3f00c8653a6668a3c8ec6
|
4
|
+
data.tar.gz: feb47f3885d7d24105b430fe0b3dbb41113dc5bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b21a0123262220156aed3a31cdcd1a5dd9314fb560a6953b1d37c331e6d8ca5bc81092eb608eab1fd784fe5b34ab541ac668928446a10536f85a1297d3ee85e
|
7
|
+
data.tar.gz: 61eb864a41ce4685515fc68fb1289e2c4ef1e2218f060bdfc91e2550c42342ad832a56b4f64627ed90bc40f1a2058518a73d264f51068b57e3e78f07ec6da0da
|
data/lib/libis/tools/config.rb
CHANGED
@@ -110,11 +110,13 @@ module Libis
|
|
110
110
|
::Logging::Layouts::Pattern.new(DEFAULT_LOG_LAYOUT_PARAMETERS)
|
111
111
|
end
|
112
112
|
|
113
|
-
def logger(name = nil)
|
113
|
+
def logger(name = nil, appenders = nil)
|
114
114
|
sync do
|
115
115
|
name ||= :root
|
116
116
|
logger = ::Logging.logger[name]
|
117
|
-
|
117
|
+
if logger.appenders.empty?
|
118
|
+
logger.appenders = appenders || ::Logging.appenders.stdout(layout: get_log_formatter)
|
119
|
+
end
|
118
120
|
logger
|
119
121
|
end
|
120
122
|
end
|
@@ -136,7 +138,7 @@ module Libis
|
|
136
138
|
::Logging::init
|
137
139
|
# noinspection RubyResolve
|
138
140
|
DEFAULT_LOG_LAYOUT_PARAMETERS = {
|
139
|
-
pattern: "%.1l, [%d #%p.%t]
|
141
|
+
pattern: "%.1l, [%d #%p.%t] %5l%X{Application}%X{Subject} : %m\n",
|
140
142
|
date_pattern: '%Y-%m-%dT%H:%M:%S.%L'
|
141
143
|
}
|
142
144
|
|
data/lib/libis/tools/logger.rb
CHANGED
@@ -47,6 +47,15 @@ module Libis
|
|
47
47
|
Config.logger
|
48
48
|
end
|
49
49
|
|
50
|
+
def set_application(name = nil)
|
51
|
+
name ||= self.class.name
|
52
|
+
::Logging.mdc['Application'] = name.blank? ? '' : " -- #{name}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_subject(name = nil)
|
56
|
+
::Logging.mdc['Subject'] = name.blank? ? '' : " - #{name}"
|
57
|
+
end
|
58
|
+
|
50
59
|
# Send a debug message to the logger.
|
51
60
|
#
|
52
61
|
# If the optional extra parameters are supplied, the first parameter will be interpreted as a format
|
data/lib/libis/tools/version.rb
CHANGED
data/libis-tools.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
33
33
|
spec.add_development_dependency 'simplecov', '~> 0.9'
|
34
34
|
spec.add_development_dependency 'equivalent-xml', '~> 0.5'
|
35
|
-
spec.add_development_dependency 'awesome_print'
|
35
|
+
spec.add_development_dependency 'awesome_print', '~> 0'
|
36
36
|
|
37
37
|
spec.add_runtime_dependency 'backports', '~> 3.6'
|
38
38
|
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
data/spec/logger_spec.rb
CHANGED
@@ -9,82 +9,157 @@ describe 'Logger' do
|
|
9
9
|
include ::Libis::Tools::Logger
|
10
10
|
end
|
11
11
|
|
12
|
-
before
|
13
|
-
|
14
|
-
|
15
|
-
before(:example) do
|
16
|
-
appender = ::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
17
|
-
::Libis::Tools::Config.logger.add_appenders(appender)
|
18
|
-
@logoutput = appender.sio
|
12
|
+
before :each do
|
13
|
+
::Libis::Tools::Config.logger.appenders =
|
14
|
+
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
19
15
|
::Libis::Tools::Config.logger.level = :all
|
20
|
-
@test_logger = TestLogger.new
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:timestamp_regex) { '\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} #\d+\.\d+\]'}
|
24
|
-
|
25
|
-
it 'should log debug output' do
|
26
|
-
@test_logger.debug 'Debug message'
|
27
|
-
puts "LOG OUTPUT: #{@logoutput.string}"
|
28
|
-
output = @logoutput.string.lines.map(&:chomp)
|
29
|
-
expect(output.size).to eq 1
|
30
|
-
expect(output.first).to match /^D, #{timestamp_regex} DEBUG : Debug message$/
|
31
16
|
end
|
32
17
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
18
|
+
let(:test_logger) { TestLogger.new }
|
19
|
+
let(:logoutput) { ::Libis::Tools::Config.logger.appenders.last.sio }
|
20
|
+
|
21
|
+
let(:timestamp_regex) { '\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} #\d+\.\d+\]' }
|
22
|
+
|
23
|
+
context 'with default log configuration' do
|
24
|
+
|
25
|
+
it 'should log debug output' do
|
26
|
+
test_logger.debug 'Debug message'
|
27
|
+
output = logoutput.string.lines.map(&:chomp)
|
28
|
+
expect(output.size).to eq 1
|
29
|
+
expect(output.last).to match /^D, #{timestamp_regex} DEBUG : Debug message$/
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should log info output' do
|
33
|
+
test_logger.info 'Info message'
|
34
|
+
output = logoutput.string.lines.map(&:chomp)
|
35
|
+
expect(output.size).to eq 1
|
36
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO : Info message$/
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should log warning output' do
|
40
|
+
test_logger.warn 'Warning message'
|
41
|
+
output = logoutput.string.lines.map(&:chomp)
|
42
|
+
expect(output.size).to eq 1
|
43
|
+
expect(output.last).to match /^W, #{timestamp_regex} WARN : Warning message$/
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should log error output' do
|
47
|
+
test_logger.error 'Error message'
|
48
|
+
output = logoutput.string.lines.map(&:chomp)
|
49
|
+
expect(output.size).to eq 1
|
50
|
+
expect(output.last).to match /^E, #{timestamp_regex} ERROR : Error message$/
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should log fatal output' do
|
54
|
+
test_logger.fatal 'Fatal message'
|
55
|
+
output = logoutput.string.lines.map(&:chomp)
|
56
|
+
expect(output.size).to eq 1
|
57
|
+
expect(output.last).to match /^F, #{timestamp_regex} FATAL : Fatal message$/
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should be quiet when asked to' do
|
61
|
+
::Libis::Tools::Config.logger.level = :error
|
62
|
+
|
63
|
+
test_logger.debug 'Debug message'
|
64
|
+
output = logoutput.string.lines.map(&:chomp)
|
65
|
+
# noinspection RubyResolve
|
66
|
+
expect(output).to be_empty
|
67
|
+
|
68
|
+
test_logger.info 'Info message'
|
69
|
+
output = logoutput.string.lines.map(&:chomp)
|
70
|
+
# noinspection RubyResolve
|
71
|
+
expect(output).to be_empty
|
72
|
+
|
73
|
+
test_logger.warn 'Warn message'
|
74
|
+
output = logoutput.string.lines.map(&:chomp)
|
75
|
+
# noinspection RubyResolve
|
76
|
+
expect(output).to be_empty
|
77
|
+
|
78
|
+
test_logger.error 'Error message'
|
79
|
+
output = logoutput.string.lines.map(&:chomp)
|
80
|
+
# noinspection RubyResolve
|
81
|
+
expect(output).not_to be_empty
|
82
|
+
|
83
|
+
test_logger.fatal 'Fatal message'
|
84
|
+
output = logoutput.string.lines.map(&:chomp)
|
85
|
+
# noinspection RubyResolve
|
86
|
+
expect(output).not_to be_empty
|
87
|
+
end
|
39
88
|
|
40
|
-
it 'should log warning output' do
|
41
|
-
@test_logger.warn 'Warning message'
|
42
|
-
output = @logoutput.string.lines.map(&:chomp)
|
43
|
-
expect(output.size).to eq 1
|
44
|
-
expect(output.first).to match /^W, #{timestamp_regex} WARN : Warning message$/
|
45
89
|
end
|
46
90
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
91
|
+
context 'with application configuration' do
|
92
|
+
|
93
|
+
it 'should print default application name' do
|
94
|
+
test_logger.set_application
|
95
|
+
test_logger.info 'Info message'
|
96
|
+
output = logoutput.string.lines.map(&:chomp)
|
97
|
+
expect(output.size).to eq 1
|
98
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO -- TestLogger : Info message$/
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should print custom application name' do
|
102
|
+
test_logger.set_application 'TestApplication'
|
103
|
+
test_logger.info 'Info message'
|
104
|
+
output = logoutput.string.lines.map(&:chomp)
|
105
|
+
expect(output.size).to eq 1
|
106
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO -- TestApplication : Info message$/
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should allow to turn of application name' do
|
110
|
+
test_logger.set_application 'TestApplication'
|
111
|
+
test_logger.info 'Info message'
|
112
|
+
output = logoutput.string.lines.map(&:chomp)
|
113
|
+
expect(output.size).to eq 1
|
114
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO -- TestApplication : Info message$/
|
115
|
+
# -- revert to default
|
116
|
+
test_logger.set_application
|
117
|
+
test_logger.info 'Info message'
|
118
|
+
output = logoutput.string.lines.map(&:chomp)
|
119
|
+
expect(output.size).to eq 2
|
120
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO -- TestLogger : Info message$/
|
121
|
+
# -- turn off
|
122
|
+
test_logger.set_application ''
|
123
|
+
test_logger.info 'Info message'
|
124
|
+
output = logoutput.string.lines.map(&:chomp)
|
125
|
+
expect(output.size).to eq 3
|
126
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO : Info message$/
|
127
|
+
end
|
53
128
|
|
54
|
-
it 'should log fatal output' do
|
55
|
-
@test_logger.fatal 'Fatal message'
|
56
|
-
output = @logoutput.string.lines.map(&:chomp)
|
57
|
-
expect(output.size).to eq 1
|
58
|
-
expect(output.first).to match /^F, #{timestamp_regex} FATAL : Fatal message$/
|
59
129
|
end
|
60
130
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
131
|
+
context 'with subject configuration' do
|
132
|
+
|
133
|
+
it 'should print no subject by default' do
|
134
|
+
test_logger.set_subject
|
135
|
+
test_logger.info 'Info message'
|
136
|
+
output = logoutput.string.lines.map(&:chomp)
|
137
|
+
expect(output.size).to eq 1
|
138
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO : Info message$/
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should print custom subject name' do
|
142
|
+
test_logger.set_subject 'TestSubject'
|
143
|
+
test_logger.info 'Info message'
|
144
|
+
output = logoutput.string.lines.map(&:chomp)
|
145
|
+
expect(output.size).to eq 1
|
146
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO - TestSubject : Info message$/
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should allow to turn off subject name' do
|
150
|
+
test_logger.set_subject 'TestSubject'
|
151
|
+
test_logger.info 'Info message'
|
152
|
+
output = logoutput.string.lines.map(&:chomp)
|
153
|
+
expect(output.size).to eq 1
|
154
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO - TestSubject : Info message$/
|
155
|
+
# -- turn off
|
156
|
+
test_logger.set_subject
|
157
|
+
test_logger.info 'Info message'
|
158
|
+
output = logoutput.string.lines.map(&:chomp)
|
159
|
+
expect(output.size).to eq 2
|
160
|
+
expect(output.last).to match /^I, #{timestamp_regex} INFO : Info message$/
|
161
|
+
end
|
162
|
+
|
88
163
|
end
|
89
164
|
|
90
|
-
end
|
165
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
name: awesome_print
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
@@ -246,7 +246,6 @@ files:
|
|
246
246
|
- ".rspec"
|
247
247
|
- ".travis.yml"
|
248
248
|
- Gemfile
|
249
|
-
- LICENSE.txt
|
250
249
|
- README.md
|
251
250
|
- Rakefile
|
252
251
|
- lib/libis-tools.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 LIBIS
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|