pantheios-ruby 0.12.2 → 0.13.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pantheios/core.rb +4 -4
- data/lib/pantheios/services/simple_console_log_service.rb +1 -1
- data/lib/pantheios/services/standard_log_service_adapter.rb +247 -0
- data/lib/pantheios/util/process_util.rb +1 -0
- data/lib/pantheios/util/thread_util.rb +2 -0
- data/lib/pantheios/util/version_util.rb +3 -0
- data/lib/pantheios/version.rb +2 -2
- data/test/unit/services/tc_standard_log_service_adapter.rb +168 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42dd156fe607cf0712c3f8bf87a4b18d00b5876f
|
4
|
+
data.tar.gz: 2fb2a26c90fb74f89b0d6ddf37e95ae26a1786f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3143dabf9f559f38711bc3f90cc849fa3b91e21f08373cfaf63d769e6f704d27197cf9d22f5d3b1108e83db388987c815b59cbca1de5642e9f987a3b61da2005
|
7
|
+
data.tar.gz: c203a65311dca3d02517ed8e1ba34b3cf2137a19d8514788a6dcb216700a2a56b07bca0f972a9981cafffb39232082b52c5cc2721e7427191697b8f077626e67
|
data/lib/pantheios/core.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: The Pantheios.Ruby core (::Pantheios::Core)
|
6
6
|
#
|
7
7
|
# Created: 2nd April 2011
|
8
|
-
# Updated:
|
8
|
+
# Updated: 23rd January 2018
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/Pantheios-Ruby
|
11
11
|
#
|
@@ -99,7 +99,7 @@ module Core
|
|
99
99
|
|
100
100
|
def set_front_end fe
|
101
101
|
|
102
|
-
raise ::TypeError, "front-end instance (#{fe.class}) does not respond to all the required messages (#{Constants_::REQUIRED_FRONTEND_METHODS.join(', ')})" unless fe && Constants_::REQUIRED_FRONTEND_METHODS.all? { |m| fe.respond_to? m }
|
102
|
+
raise ::TypeError, "front-end instance (#{fe.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_FRONTEND_METHODS.join(', ')} ])" unless fe && Constants_::REQUIRED_FRONTEND_METHODS.all? { |m| fe.respond_to? m }
|
103
103
|
|
104
104
|
r = nil
|
105
105
|
|
@@ -117,7 +117,7 @@ module Core
|
|
117
117
|
|
118
118
|
def set_back_end be
|
119
119
|
|
120
|
-
raise ::TypeError, "back-end instance (#{fe.class}) does not respond to all the required messages (#{Constants_::REQUIRED_BACKEND_METHODS.join(', ')})" unless be && Constants_::REQUIRED_BACKEND_METHODS.all? { |m| be.respond_to? m }
|
120
|
+
raise ::TypeError, "back-end instance (#{fe.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_BACKEND_METHODS.join(', ')} ])" unless be && Constants_::REQUIRED_BACKEND_METHODS.all? { |m| be.respond_to? m }
|
121
121
|
|
122
122
|
r = nil
|
123
123
|
srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
|
@@ -132,7 +132,7 @@ module Core
|
|
132
132
|
|
133
133
|
def set_service svc
|
134
134
|
|
135
|
-
raise ::TypeError, "service instance (#{svc.class}) does not respond to all the required messages (#{Constants_::REQUIRED_SERVICE_METHODS.join(', ')})" unless
|
135
|
+
raise ::TypeError, "service instance (#{svc.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_SERVICE_METHODS.join(', ')} ])" unless Constants_::REQUIRED_SERVICE_METHODS.all? { |m| svc.respond_to? m }
|
136
136
|
|
137
137
|
r = []
|
138
138
|
srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
|
@@ -53,7 +53,7 @@ require 'pantheios/application_layer/stock_severity_levels'
|
|
53
53
|
module Pantheios
|
54
54
|
module Services
|
55
55
|
|
56
|
-
# A class that fulfils the Pantheios *LogService* protocol that
|
56
|
+
# A class that fulfils the Pantheios *LogService* protocol that allows all
|
57
57
|
# severities and logs to the console (via +$stdout+ and +$stderr+)
|
58
58
|
#
|
59
59
|
# NOTE: The *LogService* protocol is implemented by a class that provides
|
@@ -0,0 +1,247 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: lib/pantheios/services/standard_log_service_adapter.rb
|
4
|
+
#
|
5
|
+
# Purpose: Definition of the
|
6
|
+
# ::Pantheios::Services::StandardLogServiceAdapter class
|
7
|
+
#
|
8
|
+
# Created: 18th June 2015
|
9
|
+
# Updated: 23rd January 2018
|
10
|
+
#
|
11
|
+
# Home: http://github.com/synesissoftware/Pantheios-Ruby
|
12
|
+
#
|
13
|
+
# Author: Matthew Wilson
|
14
|
+
#
|
15
|
+
# Copyright (c) 2015-2018, Matthew Wilson and Synesis Software
|
16
|
+
# All rights reserved.
|
17
|
+
#
|
18
|
+
# Redistribution and use in source and binary forms, with or without
|
19
|
+
# modification, are permitted provided that the following conditions are
|
20
|
+
# met:
|
21
|
+
#
|
22
|
+
# * Redistributions of source code must retain the above copyright
|
23
|
+
# notice, this list of conditions and the following disclaimer.
|
24
|
+
#
|
25
|
+
# * Redistributions in binary form must reproduce the above copyright
|
26
|
+
# notice, this list of conditions and the following disclaimer in the
|
27
|
+
# documentation and/or other materials provided with the distribution.
|
28
|
+
#
|
29
|
+
# * Neither the names of the copyright holder nor the names of its
|
30
|
+
# contributors may be used to endorse or promote products derived from
|
31
|
+
# this software without specific prior written permission.
|
32
|
+
#
|
33
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
34
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
35
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
36
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
37
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
38
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
39
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
40
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
41
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
42
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
43
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
44
|
+
#
|
45
|
+
# ######################################################################## #
|
46
|
+
|
47
|
+
|
48
|
+
require 'pantheios/application_layer/stock_severity_levels'
|
49
|
+
|
50
|
+
require 'pantheios/util/process_util'
|
51
|
+
|
52
|
+
require 'xqsr3/quality/parameter_checking'
|
53
|
+
|
54
|
+
require 'logger'
|
55
|
+
|
56
|
+
=begin
|
57
|
+
=end
|
58
|
+
|
59
|
+
module Pantheios
|
60
|
+
module Services
|
61
|
+
|
62
|
+
# An adapter class that fulfils the Pantheios *LogService* protocol in terms
|
63
|
+
# an instance of the standard Ruby logger
|
64
|
+
#
|
65
|
+
# NOTE: The *LogService* protocol is implemented by a class that provides
|
66
|
+
# the instance methods +severity_logged?(severity : Object) : boolean+ and
|
67
|
+
# +log(severity : Object, t : Time, prefix : String, msg : String)+
|
68
|
+
class StandardLogServiceAdapter
|
69
|
+
|
70
|
+
include ::Xqsr3::Quality::ParameterChecking
|
71
|
+
|
72
|
+
STOCK_SEVS_EXT2NUM = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
73
|
+
|
74
|
+
SEV_LEVELS_INT2PAIR = {
|
75
|
+
|
76
|
+
::Logger::DEBUG => [ :debug0, STOCK_SEVS_EXT2NUM[:debug0] ],
|
77
|
+
::Logger::WARN => [ :warning, STOCK_SEVS_EXT2NUM[:warning] ],
|
78
|
+
::Logger::ERROR => [ :failure, STOCK_SEVS_EXT2NUM[:failure] ],
|
79
|
+
::Logger::FATAL => [ :alert, STOCK_SEVS_EXT2NUM[:alert] ],
|
80
|
+
::Logger::UNKNOWN => [ :violation, STOCK_SEVS_EXT2NUM[:violation] ],
|
81
|
+
}
|
82
|
+
|
83
|
+
SEV_LEVELS_EXT2INT = {
|
84
|
+
|
85
|
+
:trace => ::Logger::DEBUG,
|
86
|
+
:benchmark => ::Logger::DEBUG,
|
87
|
+
|
88
|
+
:debug0 => ::Logger::DEBUG,
|
89
|
+
:debug1 => ::Logger::DEBUG,
|
90
|
+
:debug2 => ::Logger::DEBUG,
|
91
|
+
:debug3 => ::Logger::DEBUG,
|
92
|
+
:debug4 => ::Logger::DEBUG,
|
93
|
+
|
94
|
+
:notice => ::Logger::INFO,
|
95
|
+
:informational => ::Logger::INFO, :info => ::Logger::INFO,
|
96
|
+
|
97
|
+
:warning => ::Logger::WARN, :warn => ::Logger::WARN,
|
98
|
+
|
99
|
+
:failure => ::Logger::ERROR, :error => ::Logger::ERROR,
|
100
|
+
:critical => ::Logger::ERROR,
|
101
|
+
|
102
|
+
:alert => ::Logger::UNKNOWN,
|
103
|
+
:violation => ::Logger::UNKNOWN, :emergency => ::Logger::UNKNOWN,
|
104
|
+
}
|
105
|
+
|
106
|
+
SEV_LEVELS_EXT2NUM = {
|
107
|
+
|
108
|
+
STOCK_SEVS_EXT2NUM[:trace] => ::Logger::DEBUG,
|
109
|
+
STOCK_SEVS_EXT2NUM[:benchmark] => ::Logger::DEBUG,
|
110
|
+
|
111
|
+
STOCK_SEVS_EXT2NUM[:debug0] => ::Logger::DEBUG,
|
112
|
+
STOCK_SEVS_EXT2NUM[:debug1] => ::Logger::DEBUG,
|
113
|
+
STOCK_SEVS_EXT2NUM[:debug2] => ::Logger::DEBUG,
|
114
|
+
STOCK_SEVS_EXT2NUM[:debug3] => ::Logger::DEBUG,
|
115
|
+
STOCK_SEVS_EXT2NUM[:debug4] => ::Logger::DEBUG,
|
116
|
+
|
117
|
+
STOCK_SEVS_EXT2NUM[:notice] => ::Logger::INFO,
|
118
|
+
STOCK_SEVS_EXT2NUM[:informational] => ::Logger::INFO,
|
119
|
+
|
120
|
+
STOCK_SEVS_EXT2NUM[:warning] => ::Logger::WARN,
|
121
|
+
|
122
|
+
STOCK_SEVS_EXT2NUM[:failure] => ::Logger::ERROR,
|
123
|
+
STOCK_SEVS_EXT2NUM[:critical] => ::Logger::ERROR,
|
124
|
+
|
125
|
+
STOCK_SEVS_EXT2NUM[:alert] => ::Logger::UNKNOWN,
|
126
|
+
STOCK_SEVS_EXT2NUM[:violation] => ::Logger::UNKNOWN,
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
def initialize logger, adapter_threshold = nil, **options
|
131
|
+
|
132
|
+
check_parameter logger, 'logger', responds_to: [ :add, :level, :level= ]
|
133
|
+
check_parameter adapter_threshold, 'adapter_threshold', types: [ ::Integer, ::Symbol ], allow_nil: true
|
134
|
+
format = check_option options, :format, type: ::Symbol, values: [ :default, :simple, :standard ], allow_nil: true
|
135
|
+
|
136
|
+
@logger = logger
|
137
|
+
@format = format || :default
|
138
|
+
@adapter_threshold = adapter_threshold
|
139
|
+
@at_value = nil
|
140
|
+
@closed = false
|
141
|
+
end
|
142
|
+
|
143
|
+
# The threshold of the adapter, as expressed in a Pantheios severity
|
144
|
+
# level
|
145
|
+
#
|
146
|
+
# NOTE: may be +nil+, in which case the decision to determine whether to
|
147
|
+
# log (in the form of the +severity_logged?+ method) will be defered to
|
148
|
+
# the underlying logger.
|
149
|
+
attr_reader :adapter_threshold
|
150
|
+
|
151
|
+
def adapter_threshold= threshold
|
152
|
+
|
153
|
+
case @adapter_threshold = threshold
|
154
|
+
when nil
|
155
|
+
|
156
|
+
@at_value = nil
|
157
|
+
when ::Symbol
|
158
|
+
|
159
|
+
@at_value = STOCK_SEVS_EXT2NUM[threshold]
|
160
|
+
when ::Integer
|
161
|
+
|
162
|
+
@at_value = threshold
|
163
|
+
else
|
164
|
+
|
165
|
+
raise ::TypeError, 'adapter_threshold must be a symbol, an integer value, or nil'
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def close
|
170
|
+
|
171
|
+
raise "already closed" if @closed
|
172
|
+
|
173
|
+
@logger.close
|
174
|
+
|
175
|
+
@closed = true
|
176
|
+
end
|
177
|
+
|
178
|
+
def flush
|
179
|
+
|
180
|
+
@logger.flush if @logger.respond_to? :flush
|
181
|
+
end
|
182
|
+
|
183
|
+
def severity_logged? severity
|
184
|
+
|
185
|
+
case severity
|
186
|
+
when nil
|
187
|
+
|
188
|
+
return true
|
189
|
+
when adapter_threshold
|
190
|
+
|
191
|
+
return true
|
192
|
+
when ::Symbol
|
193
|
+
|
194
|
+
sev = STOCK_SEVS_EXT2NUM[severity] || 0
|
195
|
+
when ::Integer
|
196
|
+
|
197
|
+
sev = severity
|
198
|
+
else
|
199
|
+
|
200
|
+
warn "severity - '#{severity}' - of invalid type (#{severity.class}) specified to severity_logged?"
|
201
|
+
|
202
|
+
return true
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
unless adapter_threshold
|
207
|
+
|
208
|
+
# ask the logger
|
209
|
+
|
210
|
+
sym, val = SEV_LEVELS_INT2PAIR[@logger.level]
|
211
|
+
|
212
|
+
return sev <= val
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
return sev <= @at_value
|
217
|
+
end
|
218
|
+
|
219
|
+
def log severity, t, prefix, msg
|
220
|
+
|
221
|
+
sev_ext = STOCK_SEVS_EXT2NUM[severity]
|
222
|
+
sev_ext ||= severity if ::Integer === severity
|
223
|
+
sev_int = SEV_LEVELS_EXT2NUM[sev_ext]
|
224
|
+
sev_int ||= ::Logger::UNKNOWN
|
225
|
+
|
226
|
+
case @format
|
227
|
+
when :default
|
228
|
+
|
229
|
+
prog_name = ::Pantheios::Util::ProcessUtil.derive_process_name $0
|
230
|
+
|
231
|
+
@logger.add sev_int, msg, prog_name
|
232
|
+
when :simple
|
233
|
+
|
234
|
+
@logger << msg + ?\n
|
235
|
+
when :standard
|
236
|
+
|
237
|
+
@logger << "#{prefix}#{msg}\n"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
end # module Services
|
243
|
+
end # module Pantheios
|
244
|
+
|
245
|
+
# ############################## end of file ############################# #
|
246
|
+
|
247
|
+
|
data/lib/pantheios/version.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Version for Pantheios.Ruby library
|
6
6
|
#
|
7
7
|
# Created: 2nd April 2011
|
8
|
-
# Updated:
|
8
|
+
# Updated: 23rd January 2018
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/Pantheios-Ruby
|
11
11
|
#
|
@@ -50,7 +50,7 @@
|
|
50
50
|
module Pantheios
|
51
51
|
|
52
52
|
# Current version of the Pantheios.Ruby library
|
53
|
-
VERSION = '0.
|
53
|
+
VERSION = '0.13.4'
|
54
54
|
|
55
55
|
private
|
56
56
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
@@ -0,0 +1,168 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# test/unit/services/tc_standard_log_service.rb
|
4
|
+
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
|
6
|
+
|
7
|
+
require 'pantheios/services/standard_log_service_adapter'
|
8
|
+
|
9
|
+
require 'pantheios/application_layer/stock_severity_levels'
|
10
|
+
|
11
|
+
require 'pantheios/util/process_util'
|
12
|
+
|
13
|
+
require 'xqsr3/extensions/test/unit'
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
require 'stringio'
|
18
|
+
|
19
|
+
class Test_StandardLogservice < Test::Unit::TestCase
|
20
|
+
|
21
|
+
include ::Pantheios::Services
|
22
|
+
|
23
|
+
STOCK_SEVERITY_LEVEL_VALUES = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
24
|
+
|
25
|
+
def test_StandardLogServiceAdapter_type_exists
|
26
|
+
|
27
|
+
assert defined? StandardLogServiceAdapter
|
28
|
+
end
|
29
|
+
|
30
|
+
if defined?(StandardLogServiceAdapter)
|
31
|
+
|
32
|
+
def test_StandardLogServiceAdapter_type_is_a_class
|
33
|
+
|
34
|
+
assert_kind_of(::Class, StandardLogServiceAdapter)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_StandardLogServiceAdapter_type_has_expected_instance_methods
|
38
|
+
|
39
|
+
assert_type_has_instance_methods StandardLogServiceAdapter, [ :severity_logged?, :log ]
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_severity_logged
|
43
|
+
|
44
|
+
logdev = StringIO.new
|
45
|
+
logger = ::Logger.new logdev
|
46
|
+
|
47
|
+
svc = StandardLogServiceAdapter.new logger
|
48
|
+
|
49
|
+
logger.level = ::Logger::WARN
|
50
|
+
|
51
|
+
assert_false svc.severity_logged?(:debug4)
|
52
|
+
assert_false svc.severity_logged?(:debug3)
|
53
|
+
assert_false svc.severity_logged?(:debug2)
|
54
|
+
assert_false svc.severity_logged?(:debug1)
|
55
|
+
assert_false svc.severity_logged?(:debug0)
|
56
|
+
assert_false svc.severity_logged?(:informational)
|
57
|
+
assert_false svc.severity_logged?(:notice)
|
58
|
+
assert_true svc.severity_logged?(:warning)
|
59
|
+
assert_true svc.severity_logged?(:failure)
|
60
|
+
assert_true svc.severity_logged?(:critical)
|
61
|
+
assert_true svc.severity_logged?(:alert)
|
62
|
+
assert_true svc.severity_logged?(:violation)
|
63
|
+
|
64
|
+
assert_true svc.severity_logged?(nil)
|
65
|
+
|
66
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:debug4])
|
67
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:debug3])
|
68
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:debug2])
|
69
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:debug1])
|
70
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:debug0])
|
71
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:informational])
|
72
|
+
assert_false svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:notice])
|
73
|
+
assert_true svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:warning])
|
74
|
+
assert_true svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:failure])
|
75
|
+
assert_true svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:critical])
|
76
|
+
assert_true svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:alert])
|
77
|
+
assert_true svc.severity_logged?(STOCK_SEVERITY_LEVEL_VALUES[:violation])
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_selected_log_with_default_format
|
81
|
+
|
82
|
+
logdev = StringIO.new
|
83
|
+
logger = ::Logger.new logdev
|
84
|
+
|
85
|
+
svc = StandardLogServiceAdapter.new logger
|
86
|
+
|
87
|
+
logger.level = ::Logger::WARN
|
88
|
+
|
89
|
+
t = Time.now
|
90
|
+
pid = Process.pid
|
91
|
+
prname = ::Pantheios::Util::ProcessUtil.derive_process_name
|
92
|
+
|
93
|
+
[ :notice, :warning, :critical ].each do |level|
|
94
|
+
|
95
|
+
svc.log level, t, nil, "a message at #{level}" if svc.severity_logged? level
|
96
|
+
end
|
97
|
+
|
98
|
+
svc.flush if svc.respond_to? :flush
|
99
|
+
|
100
|
+
res = logdev.string.split /\n/
|
101
|
+
|
102
|
+
assert_equal 2, res.size
|
103
|
+
|
104
|
+
assert_match /W\s*,\s*\[.*##{pid}\s*\]\s*WARN\s*--\s*#{prname}\s*:\s*a message at warning/, res[0]
|
105
|
+
assert_match /E\s*,\s*\[.*##{pid}\s*\]\s*ERROR\s*--\s*#{prname}\s*:\s*a message at critical/, res[1]
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_selected_log_with_blank_format
|
109
|
+
|
110
|
+
logdev = StringIO.new
|
111
|
+
logger = ::Logger.new logdev
|
112
|
+
|
113
|
+
svc = StandardLogServiceAdapter.new logger, format: :simple
|
114
|
+
|
115
|
+
logger.level = ::Logger::WARN
|
116
|
+
|
117
|
+
t = Time.now
|
118
|
+
|
119
|
+
[ :notice, :warning, :critical ].each do |level|
|
120
|
+
|
121
|
+
svc.log level, t, nil, "a message at #{level}" if svc.severity_logged? level
|
122
|
+
end
|
123
|
+
|
124
|
+
svc.flush if svc.respond_to? :flush
|
125
|
+
|
126
|
+
res = logdev.string.split /\n/
|
127
|
+
|
128
|
+
assert_equal 2, res.size
|
129
|
+
|
130
|
+
assert_equal 'a message at warning', res[0]
|
131
|
+
assert_equal 'a message at critical', res[1]
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_selected_log_with_standard_format
|
135
|
+
|
136
|
+
logdev = StringIO.new
|
137
|
+
logger = ::Logger.new logdev
|
138
|
+
|
139
|
+
svc = StandardLogServiceAdapter.new logger, format: :standard
|
140
|
+
|
141
|
+
logger.level = ::Logger::WARN
|
142
|
+
|
143
|
+
t = Time.now
|
144
|
+
pid = Process.pid
|
145
|
+
tid = Thread.current.object_id
|
146
|
+
prname = ::Pantheios::Util::ProcessUtil.derive_process_name
|
147
|
+
ts = t.strftime '%Y-%m-%d %H:%M:%S.%6N'
|
148
|
+
|
149
|
+
[ :notice, :warning, :critical ].each do |level|
|
150
|
+
|
151
|
+
pref = "[#{prname} #{tid} #{ts} #{level}]"
|
152
|
+
|
153
|
+
svc.log level, t, pref, "a message at #{level}" if svc.severity_logged? level
|
154
|
+
end
|
155
|
+
|
156
|
+
svc.flush if svc.respond_to? :flush
|
157
|
+
|
158
|
+
res = logdev.string.split /\n/
|
159
|
+
|
160
|
+
assert_equal 2, res.size
|
161
|
+
|
162
|
+
assert_match /\s*\[\s*#{prname} #{tid} #{ts} warning\s*\]\s*a message at warning/, res[0]
|
163
|
+
assert_match /\s*\[\s*#{prname} #{tid} #{ts} critical\s*\]\s*a message at critical/, res[1]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pantheios-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xqsr3
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/pantheios/globals.rb
|
47
47
|
- lib/pantheios/services/null_log_service.rb
|
48
48
|
- lib/pantheios/services/simple_console_log_service.rb
|
49
|
+
- lib/pantheios/services/standard_log_service_adapter.rb
|
49
50
|
- lib/pantheios/util.rb
|
50
51
|
- lib/pantheios/util/process_util.rb
|
51
52
|
- lib/pantheios/util/thread_util.rb
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- test/unit/application_layer/ts_all.rb
|
60
61
|
- test/unit/services/tc_null_log_service.rb
|
61
62
|
- test/unit/services/tc_simple_console_log_service.rb
|
63
|
+
- test/unit/services/tc_standard_log_service_adapter.rb
|
62
64
|
- test/unit/services/ts_all.rb
|
63
65
|
- test/unit/ts_all.rb
|
64
66
|
- test/unit/util/tc_thread_util.rb
|