pantheios-ruby 0.22.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 +4 -4
- data/CHANGES.md +26 -0
- data/NEWS.md +1 -0
- data/TODO.md +5 -2
- data/examples/coloured_console_log_service.rb +1 -1
- data/examples/multiple_modules.rb +36 -36
- data/examples/simple_logging.rb +1 -1
- data/examples/threshold_front_end.rb +1 -1
- data/lib/pantheios/api.rb +154 -153
- data/lib/pantheios/application_layer/stock_severity_levels.rb +108 -108
- data/lib/pantheios/application_layer.rb +5 -5
- data/lib/pantheios/core.rb +415 -414
- data/lib/pantheios/front_ends/threshold_front_end.rb +79 -79
- data/lib/pantheios/globals.rb +43 -43
- data/lib/pantheios/services/coloured_console_log_service.rb +94 -94
- data/lib/pantheios/services/common/console.rb +57 -57
- data/lib/pantheios/services/multiplexing_log_service.rb +149 -148
- data/lib/pantheios/services/null_log_service.rb +9 -9
- data/lib/pantheios/services/simple_console_log_service.rb +18 -18
- data/lib/pantheios/services/simple_file_log_service.rb +110 -111
- data/lib/pantheios/services/standard_log_service_adapter.rb +117 -117
- data/lib/pantheios/util/process_util.rb +24 -24
- data/lib/pantheios/util/reflection_util.rb +13 -13
- data/lib/pantheios/util/thread_util.rb +49 -49
- data/lib/pantheios/util/version_util.rb +33 -33
- data/lib/pantheios/version.rb +12 -12
- data/lib/pantheios.rb +11 -11
- 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 +6 -6
data/lib/pantheios/core.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# ######################################################################## #
|
|
3
|
-
# File:
|
|
3
|
+
# File: lib/pantheios/core.rb
|
|
4
4
|
#
|
|
5
|
-
# Purpose:
|
|
5
|
+
# Purpose: The Pantheios.Ruby core (::Pantheios::Core)
|
|
6
6
|
#
|
|
7
|
-
# Created:
|
|
8
|
-
# Updated:
|
|
7
|
+
# Created: 2nd April 2011
|
|
8
|
+
# Updated: 30th August 2026
|
|
9
9
|
#
|
|
10
|
-
# Home:
|
|
10
|
+
# Home: https://github.com/synesissoftware/Pantheios.Ruby
|
|
11
11
|
#
|
|
12
|
-
# Author:
|
|
12
|
+
# Author: Matthew Wilson
|
|
13
13
|
#
|
|
14
|
-
# Copyright (c) 2019-
|
|
15
|
-
# Copyright (c) 2011-
|
|
14
|
+
# Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
|
|
15
|
+
# Copyright (c) 2011-2019, Matthew Wilson and Synesis Software
|
|
16
16
|
# All rights reserved.
|
|
17
17
|
#
|
|
18
18
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -61,574 +61,575 @@ require 'pantheios/util/thread_util'
|
|
|
61
61
|
module Pantheios
|
|
62
62
|
module Core
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
# @!visibility private
|
|
65
|
+
module Constants_ # :nodoc: all
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
REQUIRED_SERVICE_METHODS = %w{ severity_logged? log }.map { |name| name.to_sym }
|
|
68
|
+
REQUIRED_FRONTEND_METHODS = %w{ severity_logged? }.map { |name| name.to_sym }
|
|
69
|
+
REQUIRED_BACKEND_METHODS = %w{ log }.map { |name| name.to_sym }
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
end # module Constants_
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
# @!visibility private
|
|
74
|
+
module Internals_ # :nodoc: all
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
# @!visibility private
|
|
77
|
+
class DefaultDiscriminator # :nodoc:
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
def severity_logged? severity
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
return true if $DEBUG
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
levels = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
v_info = levels[:informational]
|
|
86
|
+
v_sev = levels[severity] if ::Symbol === severity
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
return false if v_sev > v_info
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
true
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
# @!visibility private
|
|
95
|
+
class State # :nodoc:
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
def initialize default_fe, **options
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
@mx_service = Mutex.new
|
|
100
|
+
@front_end = nil
|
|
101
|
+
@back_end = nil
|
|
102
|
+
@requires_prefix = false;
|
|
103
|
+
@default_fe = default_fe
|
|
104
|
+
end
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
def set_front_end fe
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
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 }
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
r = nil
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
fe ||= @default_fe
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
@mx_service.synchronize do
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
r, @front_end = @front_end, fe
|
|
117
|
+
end
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
r = nil if r.object_id == @default_fe.object_id
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
return r
|
|
122
|
+
end
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
def set_back_end be
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
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 }
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
r = nil
|
|
129
|
+
srp = be.respond_to?(:requires_prefix?) ? be.requires_prefix? : true
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
@mx_service.synchronize do
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
r, @back_end, @requires_prefix = @back_end, be, srp
|
|
134
|
+
end
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
return r
|
|
137
|
+
end
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
def set_service svc
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
raise ::ArgumentError, 'service instance may not be nil' if svc.nil?
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
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 }
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
raise ::TypeError, "service instance class - #{svc.class} - inherits some of the required messages - [ #{Constants_::REQUIRED_SERVICE_METHODS.join(', ')} ] - from the top-level" unless Constants_::REQUIRED_SERVICE_METHODS.all? { |m| nrcs.any? { |nr| nr.instance_methods(false).include? m } }
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
r = []
|
|
150
|
+
srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
@mx_service.synchronize do
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
r << @front_end
|
|
155
|
+
r << @back_end
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
@front_end, @back_end, @requires_prefix = svc, svc, srp
|
|
158
|
+
end
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
return r
|
|
161
|
+
end
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
if ::Pantheios::Globals.SYNCHRONISED_SEVERITY_LOGGED?
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
def severity_logged? severity
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
@mx_service.synchronize do
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
return nil unless @front_end
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
@front_end.severity_logged? severity
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
else
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
def severity_logged? severity
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
return @front_end.severity_logged? severity
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
def log
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
end
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
def discriminator
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
@mx_service.synchronize do
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
if @service && @service.respond_to?(:severity_logged?)
|
|
191
191
|
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
return @service
|
|
193
|
+
end
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
@front_end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
attr_reader :service
|
|
200
|
+
attr_reader :front_end
|
|
201
|
+
attr_reader :back_end
|
|
202
|
+
def requires_prefix?; @requires_prefix; end
|
|
203
|
+
end # class State
|
|
204
|
+
end # module Internals_
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
# @!visibility private
|
|
207
|
+
def self.included receiver # :nodoc:
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
abort "Attempt to include #{self} into #{receiver}. This is not allowed"
|
|
210
|
+
end
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
# @!visibility private
|
|
213
|
+
def self.core_init # :nodoc:
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
# process-name
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
prg_nam = nil
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
case Pantheios::Globals.PROCESS_NAME
|
|
220
|
+
when nil
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
;
|
|
223
|
+
when ::Symbol
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME
|
|
226
|
+
when ::String
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
prg_nam = Pantheios::Globals.PROCESS_NAME.strip
|
|
229
|
+
prg_nam = nil if prg_name.empty?
|
|
230
|
+
else
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
warn "ignoring unsupported Globals.PROCESS_NAME type - '#{Pantheios::Globals.PROCESS_NAME.class}'"
|
|
233
|
+
end
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
@process_name = prg_nam if prg_nam
|
|
236
236
|
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
# main thread-name
|
|
239
|
+
#
|
|
240
|
+
# This is obtained from Pantheios::Globals.MAIN_THREAD_NAME, which
|
|
241
|
+
# may be either ::String or [ ::String, ::Thread ]
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
mt_th = nil
|
|
244
|
+
mt_nam = nil
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME
|
|
247
|
+
when nil
|
|
248
248
|
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
;
|
|
250
|
+
when ::Array
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
if pg_mtn.size != 2
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE"
|
|
255
|
+
else
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
mt_th = pg_mtn[0]
|
|
258
|
+
mt_nam = pg_mtn[1]
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
if ::Thread === mt_nam
|
|
261
261
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
mt_th, mt_nam = mt_nam, mt_th
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
when ::String
|
|
266
266
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
mt_th = Thread.current
|
|
268
|
+
mt_nam = pg_mtn
|
|
269
|
+
else
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
warn "ignoring unsupported Globals.MAIN_THREAD_NAME type - '#{Pantheios::Globals.MAIN_THREAD_NAME.class}'"
|
|
272
|
+
end
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
::Pantheios::Util::ThreadUtil.set_thread_name mt_th, mt_nam if mt_nam
|
|
275
275
|
|
|
276
276
|
|
|
277
|
-
|
|
277
|
+
# state (incl. default service)
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
@@state = Internals_::State.new Internals_::DefaultDiscriminator.new
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
self.set_default_service
|
|
282
|
+
end
|
|
283
283
|
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
# @!visibility private
|
|
285
|
+
def self.set_default_service **options # :nodoc:
|
|
286
286
|
|
|
287
|
-
|
|
287
|
+
# determine which log service to initialise as the default
|
|
288
288
|
|
|
289
|
-
|
|
289
|
+
([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst|
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
next unless inst
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
|
|
293
|
+
return @@state.set_service inst
|
|
294
|
+
end
|
|
295
295
|
|
|
296
|
-
|
|
296
|
+
([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).each do |cls|
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
inst = cls.new
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
return @@state.set_service inst
|
|
301
|
+
end
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
@@state.set_service ::Pantheios::Services::SimpleConsoleLogService.new
|
|
304
|
+
end
|
|
305
305
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
306
|
+
# Sets the front-end that will be used to evaluate whether a given log
|
|
307
|
+
# statement will be logged
|
|
308
|
+
#
|
|
309
|
+
# * *Parameters:*
|
|
310
|
+
# - +fe+ The front-end instance. It must respond to the
|
|
311
|
+
# +severity_logged?+ message, or a ::TypeError will be raised
|
|
312
|
+
#
|
|
313
|
+
# * *Returns:*
|
|
314
|
+
# The previously registered instance, or +nil+ if no previous one was
|
|
315
|
+
# registered
|
|
316
|
+
def self.set_front_end fe
|
|
317
317
|
|
|
318
|
-
|
|
319
|
-
|
|
318
|
+
@@state.set_front_end fe
|
|
319
|
+
end
|
|
320
320
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
321
|
+
# Sets the back-end used to emit the given log statement
|
|
322
|
+
#
|
|
323
|
+
# * *Parameters:*
|
|
324
|
+
# - +be+ The back-end instance. It must respond to the
|
|
325
|
+
# +log+ message, or a ::TypeError will be raised. It may also respond
|
|
326
|
+
# to the +requires_prefix?+ message, which can be used to indicate
|
|
327
|
+
# whether a prepared prefix is required; if not present, the
|
|
328
|
+
# framework assumes that the back-end requires a prefix
|
|
329
|
+
#
|
|
330
|
+
# * *Returns:*
|
|
331
|
+
# The previously registered instance, or +nil+ if no previous one was
|
|
332
|
+
# registered
|
|
333
|
+
def self.set_back_end be
|
|
334
334
|
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
@@state.set_back_end be
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# Sets the service that will be used to evaluate whether a given log
|
|
339
|
+
# statement will be logged and to emit it
|
|
340
|
+
#
|
|
341
|
+
# * *Parameters:*
|
|
342
|
+
# - +svc+ The service instance. It must respond to the
|
|
343
|
+
# +severity_logged?+ and +log+ messages, or a ::TypeError will be
|
|
344
|
+
# raised. It may also respond to the +requires_prefix?+ message,
|
|
345
|
+
# which can be used to indicate whether a prepared prefix is
|
|
346
|
+
# required; if not present, the framework assumes that the service
|
|
347
|
+
# (back-end) requires a prefix
|
|
348
|
+
#
|
|
349
|
+
# * *Returns:*
|
|
350
|
+
# An array of two elements, representing the previous front-end and
|
|
351
|
+
# previous back-end
|
|
352
|
+
def self.set_service svc
|
|
337
353
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
354
|
+
@@state.set_service svc
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
self.core_init
|
|
358
|
+
|
|
359
|
+
# :nodoc:
|
|
360
|
+
def self.register_include includee, includer
|
|
361
|
+
|
|
362
|
+
$stderr.puts "#{includee} included into #{includer}" if $DEBUG
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# Default implementation to determine whether the given severity is
|
|
366
|
+
# logged
|
|
367
|
+
#
|
|
368
|
+
# * *Returns:*
|
|
369
|
+
# If +$DEBUG+ is +true+, then returns +true+ - all statements are
|
|
370
|
+
# emitted in debug mode. In normal operation, if the integral value of
|
|
371
|
+
# +severity+ is greater than that of +:informational+ then it returns
|
|
372
|
+
# +false+; otherwise it return +true+
|
|
373
|
+
def self.severity_logged? severity
|
|
374
|
+
|
|
375
|
+
@@state.severity_logged? severity
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# Default implementation to obtain the process id
|
|
379
|
+
#
|
|
380
|
+
# * *Returns:*
|
|
381
|
+
# +Process.pid+
|
|
382
|
+
def self.process_id
|
|
383
|
+
|
|
384
|
+
Process.pid
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# Default implementation to obtain the process name
|
|
388
|
+
#
|
|
389
|
+
# * *Returns:*
|
|
390
|
+
# The file stem of +$0+
|
|
391
|
+
#
|
|
392
|
+
# NOTE: this is implemented in terms of
|
|
393
|
+
# +Process_Util.derive_process_name+ and the result is cached
|
|
394
|
+
def self.process_name
|
|
395
|
+
|
|
396
|
+
@process_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# [DEPRECATED] Use +process_name+
|
|
400
|
+
def self.program_name; self.process_name; end
|
|
401
|
+
|
|
402
|
+
# Sets the process name
|
|
403
|
+
#
|
|
404
|
+
# * *Parameters:*
|
|
405
|
+
# - +name+:: [String] The (new) process name. May be +nil+, in which
|
|
406
|
+
# case +process_name+ will obtain the process name from
|
|
407
|
+
# +Process_Util.derive_process_name+
|
|
408
|
+
#
|
|
409
|
+
# * *Returns:*
|
|
410
|
+
# The previous version
|
|
411
|
+
#
|
|
412
|
+
# NOTE: to reset the value, set to +nil+
|
|
413
|
+
def self.process_name= name
|
|
414
|
+
|
|
415
|
+
previous = @process_name if defined?(@process_name)
|
|
416
|
+
@process_name = name
|
|
417
|
+
|
|
418
|
+
previous
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# [DEPRECATED] Use +process_name=+
|
|
422
|
+
def self.program_name= name; self.process_name = name; end
|
|
423
|
+
|
|
424
|
+
# Obtains a string form of the given severity
|
|
425
|
+
def self.severity_string severity
|
|
353
426
|
|
|
354
|
-
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
self.core_init
|
|
358
|
-
|
|
359
|
-
# :nodoc:
|
|
360
|
-
def self.register_include includee, includer
|
|
361
|
-
|
|
362
|
-
$stderr.puts "#{includee} included into #{includer}" if $DEBUG
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
# Default implementation to determine whether the given severity is
|
|
366
|
-
# logged
|
|
367
|
-
#
|
|
368
|
-
# * *Returns:*
|
|
369
|
-
# If +$DEBUG+ is +true+, then returns +true+ - all statements are
|
|
370
|
-
# emitted in debug mode. In normal operation, if the integral value of
|
|
371
|
-
# +severity+ is greater than that of +:informational+ then it returns
|
|
372
|
-
# +false+; otherwise it return +true+
|
|
373
|
-
def self.severity_logged? severity
|
|
374
|
-
|
|
375
|
-
@@state.severity_logged? severity
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
# Default implementation to obtain the process id
|
|
379
|
-
#
|
|
380
|
-
# * *Returns:*
|
|
381
|
-
# +Process.pid+
|
|
382
|
-
def self.process_id
|
|
383
|
-
|
|
384
|
-
Process.pid
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
# Default implementation to obtain the process name
|
|
388
|
-
#
|
|
389
|
-
# * *Returns:*
|
|
390
|
-
# The file stem of +$0+
|
|
391
|
-
#
|
|
392
|
-
# NOTE: this is implemented in terms of
|
|
393
|
-
# +Process_Util.derive_process_name+ and the result is cached
|
|
394
|
-
def self.process_name
|
|
395
|
-
|
|
396
|
-
@process_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
# [DEPRECATED] Use +process_name+
|
|
400
|
-
def self.program_name; self.process_name; end
|
|
401
|
-
|
|
402
|
-
# Sets the process name
|
|
403
|
-
#
|
|
404
|
-
# * *Parameters:*
|
|
405
|
-
# - +name+:: [String] The (new) process name. May be +nil+, in which
|
|
406
|
-
# case +process_name+ will obtain the process name from
|
|
407
|
-
# +Process_Util.derive_process_name+
|
|
408
|
-
#
|
|
409
|
-
# * *Returns:*
|
|
410
|
-
# The previous version
|
|
411
|
-
#
|
|
412
|
-
# NOTE: to reset the value, set to +nil+
|
|
413
|
-
def self.process_name= name
|
|
414
|
-
|
|
415
|
-
previous, @process_name = @process_name, name
|
|
416
|
-
|
|
417
|
-
previous
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
# [DEPRECATED] Use +process_name=+
|
|
421
|
-
def self.program_name= name; self.process_name = name; end
|
|
422
|
-
|
|
423
|
-
# Obtains a string form of the given severity
|
|
424
|
-
def self.severity_string severity
|
|
427
|
+
r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r
|
|
425
428
|
|
|
426
|
-
|
|
429
|
+
severity.to_s
|
|
430
|
+
end
|
|
427
431
|
|
|
428
|
-
|
|
429
|
-
|
|
432
|
+
# Default implementation to obtain the thread_id
|
|
433
|
+
#
|
|
434
|
+
# * *Returns:*
|
|
435
|
+
# From the current thread either the value obtained via the attribute
|
|
436
|
+
# +thread_name+ (if it responds to that) or via +object_id+
|
|
437
|
+
def self.thread_id
|
|
430
438
|
|
|
431
|
-
|
|
432
|
-
#
|
|
433
|
-
# * *Returns:*
|
|
434
|
-
# From the current thread either the value obtained via the attribute
|
|
435
|
-
# +thread_name+ (if it responds to that) or via +object_id+
|
|
436
|
-
def self.thread_id
|
|
439
|
+
t = Thread.current
|
|
437
440
|
|
|
438
|
-
|
|
441
|
+
return t.thread_name if t.respond_to? :thread_name
|
|
439
442
|
|
|
440
|
-
|
|
443
|
+
t.object_id
|
|
444
|
+
end
|
|
441
445
|
|
|
442
|
-
|
|
443
|
-
end
|
|
446
|
+
def self.timestamp_format
|
|
444
447
|
|
|
445
|
-
|
|
448
|
+
'%Y-%m-%d %H:%M:%S.%6N'
|
|
449
|
+
end
|
|
446
450
|
|
|
447
|
-
|
|
448
|
-
|
|
451
|
+
# Default implementation to obtain the timestamp according to a given
|
|
452
|
+
# format
|
|
453
|
+
#
|
|
454
|
+
# * *Parameters:*
|
|
455
|
+
# - +t+ [::Time] The time
|
|
456
|
+
# - +fmt+ [::String, nil] The format to be used. If +nil+ the value
|
|
457
|
+
# obtained by +timestamp_format+ is used
|
|
458
|
+
#
|
|
459
|
+
# * *Returns:*
|
|
460
|
+
# A string representing the time
|
|
461
|
+
def self.timestamp t, fmt
|
|
449
462
|
|
|
450
|
-
|
|
451
|
-
# format
|
|
452
|
-
#
|
|
453
|
-
# * *Parameters:*
|
|
454
|
-
# - +t+ [::Time] The time
|
|
455
|
-
# - +fmt+ [::String, nil] The format to be used. If +nil+ the value
|
|
456
|
-
# obtained by +timestamp_format+ is used
|
|
457
|
-
#
|
|
458
|
-
# * *Returns:*
|
|
459
|
-
# A string representing the time
|
|
460
|
-
def self.timestamp t, fmt
|
|
463
|
+
fmt ||= self.timestamp_format
|
|
461
464
|
|
|
462
|
-
|
|
465
|
+
t.strftime fmt
|
|
466
|
+
end
|
|
463
467
|
|
|
464
|
-
t.strftime fmt
|
|
465
|
-
end
|
|
466
468
|
|
|
467
469
|
|
|
470
|
+
# Internal implementation method, not to be called by application code
|
|
471
|
+
#
|
|
472
|
+
# @!visibility private
|
|
473
|
+
def self.get_block_value_ &block # :nodoc:
|
|
468
474
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
# @!visibility private
|
|
472
|
-
def self.get_block_value_ &block # :nodoc:
|
|
475
|
+
case block.arity
|
|
476
|
+
when 0
|
|
473
477
|
|
|
474
|
-
|
|
475
|
-
|
|
478
|
+
yield
|
|
479
|
+
when 1
|
|
476
480
|
|
|
477
|
-
|
|
478
|
-
|
|
481
|
+
yield severity
|
|
482
|
+
when 2
|
|
479
483
|
|
|
480
|
-
|
|
481
|
-
|
|
484
|
+
yield severity, argv
|
|
485
|
+
when 3
|
|
482
486
|
|
|
483
|
-
|
|
484
|
-
|
|
487
|
+
yield severity, argv, self
|
|
488
|
+
else
|
|
485
489
|
|
|
486
|
-
|
|
487
|
-
else
|
|
490
|
+
warn 'too many parameters in logging block'
|
|
488
491
|
|
|
489
|
-
|
|
492
|
+
yield severity, argv, self
|
|
493
|
+
end
|
|
494
|
+
end
|
|
490
495
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
496
|
+
# Internal implementation method, not to be called by application code
|
|
497
|
+
#
|
|
498
|
+
# @!visibility private
|
|
499
|
+
def self.log_v_impl prefix_provider, severity, argv, &block # :nodoc:
|
|
494
500
|
|
|
495
|
-
|
|
496
|
-
#
|
|
497
|
-
# @!visibility private
|
|
498
|
-
def self.log_v_impl prefix_provider, severity, argv, &block # :nodoc:
|
|
501
|
+
argv << get_block_value_(&block) if block_given?
|
|
499
502
|
|
|
500
|
-
|
|
503
|
+
self.log_raw prefix_provider, severity, argv.join
|
|
504
|
+
end
|
|
501
505
|
|
|
502
|
-
|
|
503
|
-
|
|
506
|
+
# Internal implementation method, not to be called by application code
|
|
507
|
+
#
|
|
508
|
+
# @!visibility private
|
|
509
|
+
def self.trace_v_impl prefix_provider, call_depth, param_list, severity, argv, &block # :nodoc:
|
|
504
510
|
|
|
505
|
-
|
|
506
|
-
#
|
|
507
|
-
# @!visibility private
|
|
508
|
-
def self.trace_v_impl prefix_provider, call_depth, param_list, severity, argv, &block # :nodoc:
|
|
511
|
+
unless param_list
|
|
509
512
|
|
|
510
|
-
|
|
513
|
+
if ApplicationLayer::ParamNameList === argv[0]
|
|
511
514
|
|
|
512
|
-
|
|
515
|
+
param_list = argv.shift
|
|
516
|
+
end
|
|
517
|
+
end
|
|
513
518
|
|
|
514
|
-
|
|
515
|
-
end
|
|
516
|
-
end
|
|
519
|
+
if block_given?
|
|
517
520
|
|
|
518
|
-
|
|
521
|
+
br = get_block_value_(&block)
|
|
519
522
|
|
|
520
|
-
|
|
523
|
+
if ApplicationLayer::ParamNameList === br
|
|
521
524
|
|
|
522
|
-
|
|
525
|
+
param_list = br
|
|
526
|
+
else
|
|
527
|
+
if ::Array === br
|
|
523
528
|
|
|
524
|
-
|
|
525
|
-
else
|
|
526
|
-
if ::Array === br
|
|
529
|
+
if ApplicationLayer::ParamNameList === br[0]
|
|
527
530
|
|
|
528
|
-
|
|
531
|
+
param_list = br.shift
|
|
532
|
+
end
|
|
529
533
|
|
|
530
|
-
|
|
531
|
-
|
|
534
|
+
argv += br
|
|
535
|
+
else
|
|
532
536
|
|
|
533
|
-
|
|
534
|
-
|
|
537
|
+
argv << br
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
end
|
|
535
541
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
end
|
|
542
|
+
fl = nil
|
|
543
|
+
rx = nil
|
|
544
|
+
fn = caller(call_depth + 1, 1)[0]
|
|
540
545
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
546
|
+
case param_list
|
|
547
|
+
when nil
|
|
548
|
+
;
|
|
549
|
+
when ApplicationLayer::ParamNameList
|
|
544
550
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
;
|
|
548
|
-
when ApplicationLayer::ParamNameList
|
|
551
|
+
warn "#{fn}: param_list must contain only strings or symbols" unless param_list.all? { |p| p.kind_of?(::String) || p.kind_of?(::Symbol) }
|
|
552
|
+
else
|
|
549
553
|
|
|
550
|
-
|
|
551
|
-
|
|
554
|
+
warn "#{fn}: param_list (#{param_list.class}) must be nil or an instance of #{ApplicationLayer::ParamNameList}" unless param_list
|
|
555
|
+
end
|
|
552
556
|
|
|
553
|
-
|
|
554
|
-
end
|
|
557
|
+
if ::Class === prefix_provider
|
|
555
558
|
|
|
556
|
-
|
|
559
|
+
rx = "#{prefix_provider}::"
|
|
560
|
+
else
|
|
557
561
|
|
|
558
|
-
|
|
559
|
-
|
|
562
|
+
rx = "#{prefix_provider.class}#"
|
|
563
|
+
end
|
|
560
564
|
|
|
561
|
-
|
|
562
|
-
|
|
565
|
+
if false;
|
|
566
|
+
elsif fn =~ /(.+)\:in\s*\`(.+)\'\s*$/
|
|
563
567
|
|
|
564
|
-
|
|
565
|
-
|
|
568
|
+
fl = $1
|
|
569
|
+
fn = $2
|
|
566
570
|
|
|
567
|
-
|
|
568
|
-
|
|
571
|
+
f = "#{fl}: #{rx}#{fn}"
|
|
572
|
+
elsif fn =~ /.*in\s*\`(.+)\'\s*$/
|
|
569
573
|
|
|
570
|
-
|
|
571
|
-
|
|
574
|
+
f = $1
|
|
575
|
+
else
|
|
572
576
|
|
|
573
|
-
|
|
574
|
-
|
|
577
|
+
f = fn
|
|
578
|
+
end
|
|
575
579
|
|
|
576
|
-
|
|
577
|
-
end
|
|
580
|
+
if param_list
|
|
578
581
|
|
|
579
|
-
|
|
582
|
+
sig = ''
|
|
580
583
|
|
|
581
|
-
|
|
584
|
+
argv.each_with_index do |arg, index0|
|
|
582
585
|
|
|
583
|
-
|
|
586
|
+
n = param_list[index0]
|
|
584
587
|
|
|
585
|
-
|
|
588
|
+
s = arg.to_s
|
|
589
|
+
s = "'#{s}'" if s.index(/[,\s]/)
|
|
586
590
|
|
|
587
|
-
|
|
588
|
-
s = "'#{s}'" if s.index(/[,\s]/)
|
|
591
|
+
sig += ', ' unless sig.empty?
|
|
589
592
|
|
|
590
|
-
|
|
593
|
+
sig += n ? "#{n} (#{arg.class})=#{s}" : s
|
|
594
|
+
end
|
|
595
|
+
else
|
|
591
596
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
else
|
|
597
|
+
sig = argv.join(', ')
|
|
598
|
+
end
|
|
595
599
|
|
|
596
|
-
|
|
597
|
-
end
|
|
600
|
+
stmt = "#{f}(#{sig})"
|
|
598
601
|
|
|
599
|
-
|
|
602
|
+
self.log_raw prefix_provider, severity, stmt
|
|
603
|
+
end
|
|
600
604
|
|
|
601
|
-
|
|
602
|
-
|
|
605
|
+
# Internal implementation method, not to be called by application code
|
|
606
|
+
#
|
|
607
|
+
# @!visibility private
|
|
608
|
+
def self.log_raw prefix_provider, severity, message # :nodoc:
|
|
603
609
|
|
|
604
|
-
|
|
605
|
-
#
|
|
606
|
-
# @!visibility private
|
|
607
|
-
def self.log_raw prefix_provider, severity, message # :nodoc:
|
|
610
|
+
now = Time.now
|
|
608
611
|
|
|
609
|
-
|
|
612
|
+
srp = @@state.requires_prefix?
|
|
610
613
|
|
|
611
|
-
|
|
614
|
+
case srp
|
|
615
|
+
when false
|
|
612
616
|
|
|
613
|
-
|
|
614
|
-
|
|
617
|
+
prf = nil
|
|
618
|
+
when true
|
|
615
619
|
|
|
616
|
-
|
|
617
|
-
|
|
620
|
+
prf = '[' + prefix_provider.prefix(now, severity) + ']: '
|
|
621
|
+
when :parts
|
|
618
622
|
|
|
619
|
-
|
|
620
|
-
|
|
623
|
+
prf = prefix_provider.prefix_parts(now, severity)
|
|
624
|
+
else
|
|
621
625
|
|
|
622
|
-
|
|
623
|
-
else
|
|
626
|
+
warn "invalid value '#{srp}' returned by #requires_prefix? of the Pantheios Core's state's service (which is of type #{@@state.service.class}"
|
|
624
627
|
|
|
625
|
-
|
|
628
|
+
prf = nil
|
|
629
|
+
end
|
|
626
630
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
@@state.back_end.log severity, now, prf, message
|
|
631
|
-
end
|
|
631
|
+
@@state.back_end.log severity, now, prf, message
|
|
632
|
+
end
|
|
632
633
|
|
|
633
634
|
end # Core
|
|
634
635
|
end # Pantheios
|