pantheios-ruby 0.22.0.2 → 0.22.3
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 +5 -5
- data/AUTHORS.md +21 -0
- data/CHANGES.md +337 -0
- data/CONTRIBUTING.md +36 -0
- data/EXAMPLES.md +11 -0
- data/FAQ.md +28 -0
- data/INSTALL.md +43 -0
- data/LICENSE +21 -20
- data/NEWS.md +65 -0
- data/README.md +134 -2
- data/Rakefile +21 -0
- data/SECURITY.md +23 -0
- data/TODO.md +29 -0
- data/examples/coloured_console_log_service.rb +1 -1
- data/examples/multiple_modules.md +1 -1
- data/examples/multiple_modules.rb +36 -36
- data/examples/simple_logging.md +1 -1
- data/examples/simple_logging.rb +1 -1
- data/examples/threshold_front_end.rb +1 -1
- data/lib/pantheios/api.rb +156 -155
- data/lib/pantheios/application_layer/param_name_list.rb +1 -0
- data/lib/pantheios/application_layer/stock_severity_levels.rb +110 -111
- data/lib/pantheios/application_layer.rb +6 -5
- data/lib/pantheios/core.rb +416 -415
- data/lib/pantheios/front_ends/threshold_front_end.rb +81 -81
- data/lib/pantheios/globals.rb +45 -45
- data/lib/pantheios/services/coloured_console_log_service.rb +96 -96
- data/lib/pantheios/services/common/console.rb +58 -57
- data/lib/pantheios/services/multiplexing_log_service.rb +151 -150
- data/lib/pantheios/services/null_log_service.rb +11 -11
- data/lib/pantheios/services/simple_console_log_service.rb +20 -20
- data/lib/pantheios/services/simple_file_log_service.rb +112 -113
- data/lib/pantheios/services/standard_log_service_adapter.rb +119 -119
- data/lib/pantheios/services.rb +1 -0
- data/lib/pantheios/util/process_util.rb +25 -24
- data/lib/pantheios/util/reflection_util.rb +14 -13
- data/lib/pantheios/util/thread_util.rb +50 -49
- data/lib/pantheios/util/version_util.rb +34 -33
- data/lib/pantheios/util.rb +1 -0
- data/lib/pantheios/version.rb +19 -19
- data/lib/pantheios.rb +12 -12
- data/test/performance/test_perf_simple_statements.rb +58 -58
- data/test/performance/test_perf_trace_variants.rb +43 -57
- data/test/scratch/log_rolling_by_period_daily.rb +3 -3
- data/test/scratch/log_rolling_by_size_and_depth.rb +3 -3
- data/test/scratch/log_using_blocks.rb +12 -12
- data/test/scratch/multiplexing_log_service.rb +32 -32
- data/test/unit/application_layer/tc_param_name_list.rb +13 -13
- data/test/unit/application_layer/tc_stock_severity_levels.rb +102 -102
- data/test/unit/core/tc_core_1.rb +24 -24
- data/test/unit/front_ends/tc_threshold_front_end.rb +65 -65
- data/test/unit/services/tc_multiplexing_log_service.rb +79 -79
- data/test/unit/services/tc_null_log_service.rb +42 -42
- data/test/unit/services/tc_simple_console_log_service.rb +70 -70
- data/test/unit/services/tc_simple_file_log_service.rb +146 -146
- data/test/unit/services/tc_standard_log_service_adapter.rb +94 -96
- data/test/unit/util/tc_process_util.rb +6 -6
- data/test/unit/util/tc_reflection_util.rb +20 -20
- data/test/unit/util/tc_thread_util.rb +46 -46
- data/test/unit/util/tc_version_util.rb +47 -47
- metadata +33 -12
|
@@ -17,236 +17,236 @@ require 'tempfile'
|
|
|
17
17
|
|
|
18
18
|
class Test_SimpleFileLogservice < Test::Unit::TestCase
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
include ::Pantheios::Services
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
def test_SimpleFileLogService_type_exists
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
assert defined? SimpleFileLogService
|
|
25
|
+
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
if defined?(SimpleFileLogService)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
def self.log_to_StringIO_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
def_t ||= Time.now
|
|
32
|
+
def_pref ||= "[prog, thread, #{def_t}]: "
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
stream = StringIO.new
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
svc = SimpleFileLogService.new stream, **options
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
messages.each do |message|
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
ar = ::Array === message ? message : [ message ]
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
msg = ar[0]
|
|
43
|
+
sev = ar[1] || def_sev
|
|
44
|
+
pref = ar[2] || def_pref
|
|
45
|
+
t = ar[3] || def_t
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
svc.log sev, t, pref, msg
|
|
48
|
+
end
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
stream.string
|
|
51
|
+
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
def self.log_to_Tempfile_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
def_t ||= Time.now
|
|
56
|
+
def_pref ||= "[prog, thread, #{def_t}]: "
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
tf = Tempfile.new 'Pantheios.Ruby.Tempfile'
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
begin
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
svc = SimpleFileLogService.new tf, **options
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
messages.each do |message|
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
ar = ::Array === message ? message : [ message ]
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
msg = ar[0]
|
|
69
|
+
sev = ar[1] || def_sev
|
|
70
|
+
pref = ar[2] || def_pref
|
|
71
|
+
t = ar[3] || def_t
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
svc.log sev, t, pref, msg
|
|
74
|
+
end
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
tf.rewind
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return tf.read
|
|
79
|
+
ensure
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
tf.close
|
|
82
|
+
tf.unlink
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
def self.log_to_Tempfile_path_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
def_t ||= Time.now
|
|
89
|
+
def_pref ||= "[prog, thread, #{def_t}]: "
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
tf = Tempfile.new 'Pantheios.Ruby.Tempfile'
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
begin
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
svc = SimpleFileLogService.new tf.path, **options
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
messages.each do |message|
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
ar = ::Array === message ? message : [ message ]
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
msg = ar[0]
|
|
102
|
+
sev = ar[1] || def_sev
|
|
103
|
+
pref = ar[2] || def_pref
|
|
104
|
+
t = ar[3] || def_t
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
svc.log sev, t, pref, msg
|
|
107
|
+
end
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
tf.rewind
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
return tf.read
|
|
112
|
+
ensure
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
tf.close
|
|
115
|
+
tf.unlink
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
def test_SimpleFileLogService_type_is_a_class
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
assert_kind_of(::Class, SimpleFileLogService)
|
|
122
|
+
end
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
def test_SimpleFileLogService_type_has_expected_instance_methods
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
assert_type_has_instance_methods SimpleFileLogService, [ :severity_logged?, :log ]
|
|
127
|
+
end
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
def test_ctor_failures_with_invalid_log_file_or_path
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
assert_raise_with_message(::ArgumentError, /log_file_or_path.*not.*nil/) { SimpleFileLogService.new nil }
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
assert_raise_with_message(::TypeError, [ /log_file_or_path.*must be/, /::File/, /::IO/, /::String/, /::StringIO/ ]) { SimpleFileLogService.new(//) }
|
|
134
|
+
end
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
def test_ctor_failures_with_invalid_options
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
assert_raise_with_message(::ArgumentError, /:roll_depth.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_depth: true }
|
|
139
|
+
assert_raise_with_message(::ArgumentError, /:roll_depth.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_depth: -1 }
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
assert_raise_with_message(::ArgumentError, /:roll_size.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_size: true }
|
|
142
|
+
assert_raise_with_message(::ArgumentError, /:roll_size.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_size: -1 }
|
|
143
|
+
end
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
def test_severity_logged_false_with_large_range_of_integers
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
output = StringIO.new
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
svc = SimpleFileLogService.new output
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
(-10000 .. 10000).each do |sev|
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
assert_true(svc.severity_logged?(sev), "severity '#{sev}' (#{sev.class}) was not logged")
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
def test_simple_logging_with_StringIO_1
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
message = 'msg'
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
output = self.class.log_to_StringIO_and_get_output [ message ], :notice, nil, nil
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
lines = output.split(/\n/)
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
assert_not_empty lines
|
|
166
|
+
assert_equal 1, lines.size
|
|
167
|
+
assert_match(/msg$/, lines[0])
|
|
168
|
+
end
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
def test_simple_logging_with_StringIO_2
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
msgs = [
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
[ 'msg-1' ],
|
|
175
|
+
[ 'msg-2' ],
|
|
176
|
+
]
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
output = self.class.log_to_StringIO_and_get_output msgs, :notice, nil, nil
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
lines = output.split(/\n/)
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
assert_not_empty lines
|
|
183
|
+
assert_equal 2, lines.size
|
|
184
|
+
assert_match(/msg-1$/, lines[0])
|
|
185
|
+
assert_match(/msg-2$/, lines[1])
|
|
186
|
+
end
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
def test_simple_logging_with_Tempfile_1
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
message = 'msg'
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
output = self.class.log_to_Tempfile_and_get_output [ message ], :notice, nil, nil
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
lines = output.split(/\n/)
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
assert_not_empty lines
|
|
197
|
+
assert_equal 1, lines.size
|
|
198
|
+
assert_match(/msg$/, lines[0])
|
|
199
|
+
end
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
def test_simple_logging_with_Tempfile_2
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
msgs = [
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
[ 'msg-1' ],
|
|
206
|
+
[ 'msg-2' ],
|
|
207
|
+
]
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
output = self.class.log_to_Tempfile_and_get_output msgs, :notice, nil, nil
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
lines = output.split(/\n/)
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
assert_not_empty lines
|
|
214
|
+
assert_equal 2, lines.size
|
|
215
|
+
assert_match(/msg-1$/, lines[0])
|
|
216
|
+
assert_match(/msg-2$/, lines[1])
|
|
217
|
+
end
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
def test_simple_logging_with_Tempfile_path_1
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
message = 'msg'
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
output = self.class.log_to_Tempfile_path_and_get_output [ message ], :notice, nil, nil
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
lines = output.split(/\n/)
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
assert_not_empty lines
|
|
228
|
+
assert_equal 1, lines.size
|
|
229
|
+
assert_match(/msg$/, lines[0])
|
|
230
|
+
end
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
def test_simple_logging_with_Tempfile_path_2
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
msgs = [
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
[ 'msg-1' ],
|
|
237
|
+
[ 'msg-2' ],
|
|
238
|
+
]
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
output = self.class.log_to_Tempfile_path_and_get_output msgs, :notice, nil, nil
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
lines = output.split(/\n/)
|
|
243
243
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
244
|
+
assert_not_empty lines
|
|
245
|
+
assert_equal 2, lines.size
|
|
246
|
+
assert_match(/msg-1$/, lines[0])
|
|
247
|
+
assert_match(/msg-2$/, lines[1])
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
|
|
@@ -18,151 +18,149 @@ require 'stringio'
|
|
|
18
18
|
|
|
19
19
|
class Test_StandardLogservice < Test::Unit::TestCase
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
include ::Pantheios::Services
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
STOCK_SEVERITY_LEVEL_VALUES = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
def test_StandardLogServiceAdapter_type_exists
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
assert defined? StandardLogServiceAdapter
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
if defined?(StandardLogServiceAdapter)
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
def test_StandardLogServiceAdapter_type_is_a_class
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
assert_kind_of(::Class, StandardLogServiceAdapter)
|
|
35
|
+
end
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
def test_StandardLogServiceAdapter_type_has_expected_instance_methods
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
assert_type_has_instance_methods StandardLogServiceAdapter, [ :severity_logged?, :log ]
|
|
40
|
+
end
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
def test_severity_logged
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
logdev = StringIO.new
|
|
45
|
+
logger = ::Logger.new logdev
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
svc = StandardLogServiceAdapter.new logger
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
logger.level = ::Logger::WARN
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
63
|
|
|
64
|
-
|
|
64
|
+
assert_true svc.severity_logged?(nil)
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
79
|
|
|
80
|
-
|
|
80
|
+
def test_selected_log_with_default_format
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
logdev = StringIO.new
|
|
83
|
+
logger = ::Logger.new logdev
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
svc = StandardLogServiceAdapter.new logger
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
logger.level = ::Logger::WARN
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
prname = ::Pantheios::Util::ProcessUtil.derive_process_name
|
|
89
|
+
t = Time.now
|
|
90
|
+
prname = ::Pantheios::Util::ProcessUtil.derive_process_name
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
[ :notice, :warning, :critical ].each do |level|
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
svc.log level, t, nil, "a message at #{level}" if svc.severity_logged? level
|
|
95
|
+
end
|
|
97
96
|
|
|
98
|
-
|
|
97
|
+
svc.flush if svc.respond_to? :flush
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
res = logdev.string.split(/\n/)
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
assert_equal 2, res.size
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
assert_match(/W\s*,\s*\[.*##{Process.pid}\s*\]\s*WARN\s*--\s*#{prname}\s*:\s*a message at warning/, res[0])
|
|
104
|
+
assert_match(/E\s*,\s*\[.*##{Process.pid}\s*\]\s*ERROR\s*--\s*#{prname}\s*:\s*a message at critical/, res[1])
|
|
105
|
+
end
|
|
107
106
|
|
|
108
|
-
|
|
107
|
+
def test_selected_log_with_blank_format
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
logdev = StringIO.new
|
|
110
|
+
logger = ::Logger.new logdev
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
svc = StandardLogServiceAdapter.new logger, format: :simple
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
logger.level = ::Logger::WARN
|
|
116
115
|
|
|
117
|
-
|
|
116
|
+
t = Time.now
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
[ :notice, :warning, :critical ].each do |level|
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
svc.log level, t, nil, "a message at #{level}" if svc.severity_logged? level
|
|
121
|
+
end
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
svc.flush if svc.respond_to? :flush
|
|
125
124
|
|
|
126
|
-
|
|
125
|
+
res = logdev.string.split(/\n/)
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
assert_equal 2, res.size
|
|
129
128
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
assert_equal 'a message at warning', res[0]
|
|
130
|
+
assert_equal 'a message at critical', res[1]
|
|
131
|
+
end
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
def test_selected_log_with_standard_format
|
|
135
134
|
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
logdev = StringIO.new
|
|
136
|
+
logger = ::Logger.new logdev
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
svc = StandardLogServiceAdapter.new logger, format: :standard
|
|
140
139
|
|
|
141
|
-
|
|
140
|
+
logger.level = ::Logger::WARN
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
ts = t.strftime '%Y-%m-%d %H:%M:%S.%6N'
|
|
142
|
+
t = Time.now
|
|
143
|
+
tid = Thread.current.object_id
|
|
144
|
+
prname = ::Pantheios::Util::ProcessUtil.derive_process_name
|
|
145
|
+
ts = t.strftime '%Y-%m-%d %H:%M:%S.%6N'
|
|
148
146
|
|
|
149
|
-
|
|
147
|
+
[ :notice, :warning, :critical ].each do |level|
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
pref = "[#{prname} #{tid} #{ts} #{level}]"
|
|
152
150
|
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
svc.log level, t, pref, "a message at #{level}" if svc.severity_logged? level
|
|
152
|
+
end
|
|
155
153
|
|
|
156
|
-
|
|
154
|
+
svc.flush if svc.respond_to? :flush
|
|
157
155
|
|
|
158
|
-
|
|
156
|
+
res = logdev.string.split(/\n/)
|
|
159
157
|
|
|
160
|
-
|
|
158
|
+
assert_equal 2, res.size
|
|
161
159
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
assert_match(/\s*\[\s*#{prname} #{tid} #{ts} warning\s*\]\s*a message at warning/, res[0])
|
|
161
|
+
assert_match(/\s*\[\s*#{prname} #{tid} #{ts} critical\s*\]\s*a message at critical/, res[1])
|
|
162
|
+
end
|
|
163
|
+
end
|
|
166
164
|
end
|
|
167
165
|
|
|
168
166
|
|
|
@@ -10,15 +10,15 @@ require 'test/unit'
|
|
|
10
10
|
|
|
11
11
|
class Test_ProcessUtil_set_thread_name < Test::Unit::TestCase
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
PU = ::Pantheios::Util::ProcessUtil
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
def test_derive_process_name
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
assert_equal 'abc', PU.derive_process_name('abc')
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
assert_equal 'abc', PU.derive_process_name('abc.rb')
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
assert_equal 'abc', PU.derive_process_name('abc.rb')
|
|
22
|
+
end
|
|
23
23
|
end
|
|
24
24
|
|