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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +26 -0
  3. data/NEWS.md +1 -0
  4. data/TODO.md +5 -2
  5. data/examples/coloured_console_log_service.rb +1 -1
  6. data/examples/multiple_modules.rb +36 -36
  7. data/examples/simple_logging.rb +1 -1
  8. data/examples/threshold_front_end.rb +1 -1
  9. data/lib/pantheios/api.rb +154 -153
  10. data/lib/pantheios/application_layer/stock_severity_levels.rb +108 -108
  11. data/lib/pantheios/application_layer.rb +5 -5
  12. data/lib/pantheios/core.rb +415 -414
  13. data/lib/pantheios/front_ends/threshold_front_end.rb +79 -79
  14. data/lib/pantheios/globals.rb +43 -43
  15. data/lib/pantheios/services/coloured_console_log_service.rb +94 -94
  16. data/lib/pantheios/services/common/console.rb +57 -57
  17. data/lib/pantheios/services/multiplexing_log_service.rb +149 -148
  18. data/lib/pantheios/services/null_log_service.rb +9 -9
  19. data/lib/pantheios/services/simple_console_log_service.rb +18 -18
  20. data/lib/pantheios/services/simple_file_log_service.rb +110 -111
  21. data/lib/pantheios/services/standard_log_service_adapter.rb +117 -117
  22. data/lib/pantheios/util/process_util.rb +24 -24
  23. data/lib/pantheios/util/reflection_util.rb +13 -13
  24. data/lib/pantheios/util/thread_util.rb +49 -49
  25. data/lib/pantheios/util/version_util.rb +33 -33
  26. data/lib/pantheios/version.rb +12 -12
  27. data/lib/pantheios.rb +11 -11
  28. data/test/performance/test_perf_simple_statements.rb +58 -58
  29. data/test/performance/test_perf_trace_variants.rb +43 -57
  30. data/test/scratch/log_rolling_by_period_daily.rb +3 -3
  31. data/test/scratch/log_rolling_by_size_and_depth.rb +3 -3
  32. data/test/scratch/log_using_blocks.rb +12 -12
  33. data/test/scratch/multiplexing_log_service.rb +32 -32
  34. data/test/unit/application_layer/tc_param_name_list.rb +13 -13
  35. data/test/unit/application_layer/tc_stock_severity_levels.rb +102 -102
  36. data/test/unit/core/tc_core_1.rb +24 -24
  37. data/test/unit/front_ends/tc_threshold_front_end.rb +65 -65
  38. data/test/unit/services/tc_multiplexing_log_service.rb +79 -79
  39. data/test/unit/services/tc_null_log_service.rb +42 -42
  40. data/test/unit/services/tc_simple_console_log_service.rb +70 -70
  41. data/test/unit/services/tc_simple_file_log_service.rb +146 -146
  42. data/test/unit/services/tc_standard_log_service_adapter.rb +94 -96
  43. data/test/unit/util/tc_process_util.rb +6 -6
  44. data/test/unit/util/tc_reflection_util.rb +20 -20
  45. data/test/unit/util/tc_thread_util.rb +46 -46
  46. data/test/unit/util/tc_version_util.rb +47 -47
  47. metadata +6 -6
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
  # ######################################################################## #
3
- # File: lib/pantheios/core.rb
3
+ # File: lib/pantheios/core.rb
4
4
  #
5
- # Purpose: The Pantheios.Ruby core (::Pantheios::Core)
5
+ # Purpose: The Pantheios.Ruby core (::Pantheios::Core)
6
6
  #
7
- # Created: 2nd April 2011
8
- # Updated: 15th August 2026
7
+ # Created: 2nd April 2011
8
+ # Updated: 30th August 2026
9
9
  #
10
- # Home: https://github.com/synesissoftware/Pantheios.Ruby
10
+ # Home: https://github.com/synesissoftware/Pantheios.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
15
- # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
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
- # @!visibility private
65
- module Constants_ # :nodoc: all
64
+ # @!visibility private
65
+ module Constants_ # :nodoc: all
66
66
 
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 }
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
- end # module Constants_
71
+ end # module Constants_
72
72
 
73
- # @!visibility private
74
- module Internals_ # :nodoc: all
73
+ # @!visibility private
74
+ module Internals_ # :nodoc: all
75
75
 
76
- # @!visibility private
77
- class DefaultDiscriminator # :nodoc:
76
+ # @!visibility private
77
+ class DefaultDiscriminator # :nodoc:
78
78
 
79
- def severity_logged? severity
79
+ def severity_logged? severity
80
80
 
81
- return true if $DEBUG
81
+ return true if $DEBUG
82
82
 
83
- levels = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
83
+ levels = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
84
84
 
85
- v_info = levels[:informational]
86
- v_sev = levels[severity] if ::Symbol === severity
85
+ v_info = levels[:informational]
86
+ v_sev = levels[severity] if ::Symbol === severity
87
87
 
88
- return false if v_sev > v_info
88
+ return false if v_sev > v_info
89
89
 
90
- true
91
- end
92
- end
90
+ true
91
+ end
92
+ end
93
93
 
94
- # @!visibility private
95
- class State # :nodoc:
94
+ # @!visibility private
95
+ class State # :nodoc:
96
96
 
97
- def initialize default_fe, **options
97
+ def initialize default_fe, **options
98
98
 
99
- @mx_service = Mutex.new
100
- @front_end = nil
101
- @back_end = nil
102
- @requires_prefix = false;
103
- @default_fe = default_fe
104
- end
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
- def set_front_end fe
106
+ def set_front_end fe
107
107
 
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 }
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
- r = nil
110
+ r = nil
111
111
 
112
- fe ||= @default_fe
112
+ fe ||= @default_fe
113
113
 
114
- @mx_service.synchronize do
114
+ @mx_service.synchronize do
115
115
 
116
- r, @front_end = @front_end, fe
117
- end
116
+ r, @front_end = @front_end, fe
117
+ end
118
118
 
119
- r = nil if r.object_id == @default_fe.object_id
119
+ r = nil if r.object_id == @default_fe.object_id
120
120
 
121
- return r
122
- end
121
+ return r
122
+ end
123
123
 
124
- def set_back_end be
124
+ def set_back_end be
125
125
 
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 }
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
- r = nil
129
- srp = be.respond_to?(:requires_prefix?) ? be.requires_prefix? : true
128
+ r = nil
129
+ srp = be.respond_to?(:requires_prefix?) ? be.requires_prefix? : true
130
130
 
131
- @mx_service.synchronize do
131
+ @mx_service.synchronize do
132
132
 
133
- r, @back_end, @requires_prefix = @back_end, be, srp
134
- end
133
+ r, @back_end, @requires_prefix = @back_end, be, srp
134
+ end
135
135
 
136
- return r
137
- end
136
+ return r
137
+ end
138
138
 
139
- def set_service svc
139
+ def set_service svc
140
140
 
141
- raise ::ArgumentError, 'service instance may not be nil' if svc.nil?
141
+ raise ::ArgumentError, 'service instance may not be nil' if svc.nil?
142
142
 
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 }
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
- nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc
145
+ nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc
146
146
 
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 } }
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
- r = []
150
- srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
149
+ r = []
150
+ srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
151
151
 
152
- @mx_service.synchronize do
152
+ @mx_service.synchronize do
153
153
 
154
- r << @front_end
155
- r << @back_end
154
+ r << @front_end
155
+ r << @back_end
156
156
 
157
- @front_end, @back_end, @requires_prefix = svc, svc, srp
158
- end
157
+ @front_end, @back_end, @requires_prefix = svc, svc, srp
158
+ end
159
159
 
160
- return r
161
- end
160
+ return r
161
+ end
162
162
 
163
- if ::Pantheios::Globals.SYNCHRONISED_SEVERITY_LOGGED?
163
+ if ::Pantheios::Globals.SYNCHRONISED_SEVERITY_LOGGED?
164
164
 
165
- def severity_logged? severity
165
+ def severity_logged? severity
166
166
 
167
- @mx_service.synchronize do
167
+ @mx_service.synchronize do
168
168
 
169
- return nil unless @front_end
169
+ return nil unless @front_end
170
170
 
171
- @front_end.severity_logged? severity
172
- end
173
- end
174
- else
171
+ @front_end.severity_logged? severity
172
+ end
173
+ end
174
+ else
175
175
 
176
- def severity_logged? severity
176
+ def severity_logged? severity
177
177
 
178
- return @front_end.severity_logged? severity
179
- end
180
- end
178
+ return @front_end.severity_logged? severity
179
+ end
180
+ end
181
181
 
182
- def log
182
+ def log
183
183
 
184
- end
184
+ end
185
185
 
186
- def discriminator
186
+ def discriminator
187
187
 
188
- @mx_service.synchronize do
188
+ @mx_service.synchronize do
189
189
 
190
- if @service && @service.respond_to?(:severity_logged?)
190
+ if @service && @service.respond_to?(:severity_logged?)
191
191
 
192
- return @service
193
- end
192
+ return @service
193
+ end
194
194
 
195
- @front_end
196
- end
197
- end
195
+ @front_end
196
+ end
197
+ end
198
198
 
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_
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
- # @!visibility private
207
- def self.included receiver # :nodoc:
206
+ # @!visibility private
207
+ def self.included receiver # :nodoc:
208
208
 
209
- abort "Attempt to include #{self} into #{receiver}. This is not allowed"
210
- end
209
+ abort "Attempt to include #{self} into #{receiver}. This is not allowed"
210
+ end
211
211
 
212
- # @!visibility private
213
- def self.core_init # :nodoc:
212
+ # @!visibility private
213
+ def self.core_init # :nodoc:
214
214
 
215
- # process-name
215
+ # process-name
216
216
 
217
- prg_nam = nil
217
+ prg_nam = nil
218
218
 
219
- case Pantheios::Globals.PROCESS_NAME
220
- when nil
219
+ case Pantheios::Globals.PROCESS_NAME
220
+ when nil
221
221
 
222
- ;
223
- when ::Symbol
222
+ ;
223
+ when ::Symbol
224
224
 
225
- prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME
226
- when ::String
225
+ prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME
226
+ when ::String
227
227
 
228
- prg_nam = Pantheios::Globals.PROCESS_NAME.strip
229
- prg_nam = nil if prg_name.empty?
230
- else
228
+ prg_nam = Pantheios::Globals.PROCESS_NAME.strip
229
+ prg_nam = nil if prg_name.empty?
230
+ else
231
231
 
232
- warn "ignoring unsupported Globals.PROCESS_NAME type - '#{Pantheios::Globals.PROCESS_NAME.class}'"
233
- end
232
+ warn "ignoring unsupported Globals.PROCESS_NAME type - '#{Pantheios::Globals.PROCESS_NAME.class}'"
233
+ end
234
234
 
235
- @process_name = prg_nam if prg_nam
235
+ @process_name = prg_nam if prg_nam
236
236
 
237
237
 
238
- # main thread-name
239
- #
240
- # This is obtained from Pantheios::Globals.MAIN_THREAD_NAME, which
241
- # may be either ::String or [ ::String, ::Thread ]
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
- mt_th = nil
244
- mt_nam = nil
243
+ mt_th = nil
244
+ mt_nam = nil
245
245
 
246
- case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME
247
- when nil
246
+ case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME
247
+ when nil
248
248
 
249
- ;
250
- when ::Array
249
+ ;
250
+ when ::Array
251
251
 
252
- if pg_mtn.size != 2
252
+ if pg_mtn.size != 2
253
253
 
254
- warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE"
255
- else
254
+ warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE"
255
+ else
256
256
 
257
- mt_th = pg_mtn[0]
258
- mt_nam = pg_mtn[1]
257
+ mt_th = pg_mtn[0]
258
+ mt_nam = pg_mtn[1]
259
259
 
260
- if ::Thread === mt_nam
260
+ if ::Thread === mt_nam
261
261
 
262
- mt_th, mt_nam = mt_nam, mt_th
263
- end
264
- end
265
- when ::String
262
+ mt_th, mt_nam = mt_nam, mt_th
263
+ end
264
+ end
265
+ when ::String
266
266
 
267
- mt_th = Thread.current
268
- mt_nam = pg_mtn
269
- else
267
+ mt_th = Thread.current
268
+ mt_nam = pg_mtn
269
+ else
270
270
 
271
- warn "ignoring unsupported Globals.MAIN_THREAD_NAME type - '#{Pantheios::Globals.MAIN_THREAD_NAME.class}'"
272
- end
271
+ warn "ignoring unsupported Globals.MAIN_THREAD_NAME type - '#{Pantheios::Globals.MAIN_THREAD_NAME.class}'"
272
+ end
273
273
 
274
- ::Pantheios::Util::ThreadUtil.set_thread_name mt_th, mt_nam if mt_nam
274
+ ::Pantheios::Util::ThreadUtil.set_thread_name mt_th, mt_nam if mt_nam
275
275
 
276
276
 
277
- # state (incl. default service)
277
+ # state (incl. default service)
278
278
 
279
- @@state = Internals_::State.new Internals_::DefaultDiscriminator.new
279
+ @@state = Internals_::State.new Internals_::DefaultDiscriminator.new
280
280
 
281
- self.set_default_service
282
- end
281
+ self.set_default_service
282
+ end
283
283
 
284
- # @!visibility private
285
- def self.set_default_service **options # :nodoc:
284
+ # @!visibility private
285
+ def self.set_default_service **options # :nodoc:
286
286
 
287
- # determine which log service to initialise as the default
287
+ # determine which log service to initialise as the default
288
288
 
289
- ([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst|
289
+ ([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst|
290
290
 
291
- next unless inst
291
+ next unless inst
292
292
 
293
- return @@state.set_service inst
294
- end
293
+ return @@state.set_service inst
294
+ end
295
295
 
296
- ([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).each do |cls|
296
+ ([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).each do |cls|
297
297
 
298
- inst = cls.new
298
+ inst = cls.new
299
299
 
300
- return @@state.set_service inst
301
- end
300
+ return @@state.set_service inst
301
+ end
302
302
 
303
- @@state.set_service ::Pantheios::Services::SimpleConsoleLogService.new
304
- end
303
+ @@state.set_service ::Pantheios::Services::SimpleConsoleLogService.new
304
+ end
305
305
 
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
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
- @@state.set_front_end fe
319
- end
318
+ @@state.set_front_end fe
319
+ end
320
320
 
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
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
- @@state.set_back_end be
336
- end
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
- # 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
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
- @@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 = @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
- r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r
429
+ severity.to_s
430
+ end
427
431
 
428
- severity.to_s
429
- end
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
- # Default implementation to obtain the thread_id
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
- t = Thread.current
441
+ return t.thread_name if t.respond_to? :thread_name
439
442
 
440
- return t.thread_name if t.respond_to? :thread_name
443
+ t.object_id
444
+ end
441
445
 
442
- t.object_id
443
- end
446
+ def self.timestamp_format
444
447
 
445
- def self.timestamp_format
448
+ '%Y-%m-%d %H:%M:%S.%6N'
449
+ end
446
450
 
447
- '%Y-%m-%d %H:%M:%S.%6N'
448
- end
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
- # Default implementation to obtain the timestamp according to a given
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
- fmt ||= self.timestamp_format
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
- # Internal implementation method, not to be called by application code
470
- #
471
- # @!visibility private
472
- def self.get_block_value_ &block # :nodoc:
475
+ case block.arity
476
+ when 0
473
477
 
474
- case block.arity
475
- when 0
478
+ yield
479
+ when 1
476
480
 
477
- yield
478
- when 1
481
+ yield severity
482
+ when 2
479
483
 
480
- yield severity
481
- when 2
484
+ yield severity, argv
485
+ when 3
482
486
 
483
- yield severity, argv
484
- when 3
487
+ yield severity, argv, self
488
+ else
485
489
 
486
- yield severity, argv, self
487
- else
490
+ warn 'too many parameters in logging block'
488
491
 
489
- warn 'too many parameters in logging block'
492
+ yield severity, argv, self
493
+ end
494
+ end
490
495
 
491
- yield severity, argv, self
492
- end
493
- end
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
- # Internal implementation method, not to be called by application code
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
- argv << get_block_value_(&block) if block_given?
503
+ self.log_raw prefix_provider, severity, argv.join
504
+ end
501
505
 
502
- self.log_raw prefix_provider, severity, argv.join
503
- end
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
- # Internal implementation method, not to be called by application code
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
- unless param_list
513
+ if ApplicationLayer::ParamNameList === argv[0]
511
514
 
512
- if ApplicationLayer::ParamNameList === argv[0]
515
+ param_list = argv.shift
516
+ end
517
+ end
513
518
 
514
- param_list = argv.shift
515
- end
516
- end
519
+ if block_given?
517
520
 
518
- if block_given?
521
+ br = get_block_value_(&block)
519
522
 
520
- br = get_block_value_(&block)
523
+ if ApplicationLayer::ParamNameList === br
521
524
 
522
- if ApplicationLayer::ParamNameList === br
525
+ param_list = br
526
+ else
527
+ if ::Array === br
523
528
 
524
- param_list = br
525
- else
526
- if ::Array === br
529
+ if ApplicationLayer::ParamNameList === br[0]
527
530
 
528
- if ApplicationLayer::ParamNameList === br[0]
531
+ param_list = br.shift
532
+ end
529
533
 
530
- param_list = br.shift
531
- end
534
+ argv += br
535
+ else
532
536
 
533
- argv += br
534
- else
537
+ argv << br
538
+ end
539
+ end
540
+ end
535
541
 
536
- argv << br
537
- end
538
- end
539
- end
542
+ fl = nil
543
+ rx = nil
544
+ fn = caller(call_depth + 1, 1)[0]
540
545
 
541
- fl = nil
542
- rx = nil
543
- fn = caller(call_depth + 1, 1)[0]
546
+ case param_list
547
+ when nil
548
+ ;
549
+ when ApplicationLayer::ParamNameList
544
550
 
545
- case param_list
546
- when nil
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
- warn "#{fn}: param_list must contain only strings or symbols" unless param_list.all? { |p| p.kind_of?(::String) || p.kind_of?(::Symbol) }
551
- else
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
- warn "#{fn}: param_list (#{param_list.class}) must be nil or an instance of #{ApplicationLayer::ParamNameList}" unless param_list
554
- end
557
+ if ::Class === prefix_provider
555
558
 
556
- if ::Class === prefix_provider
559
+ rx = "#{prefix_provider}::"
560
+ else
557
561
 
558
- rx = "#{prefix_provider}::"
559
- else
562
+ rx = "#{prefix_provider.class}#"
563
+ end
560
564
 
561
- rx = "#{prefix_provider.class}#"
562
- end
565
+ if false;
566
+ elsif fn =~ /(.+)\:in\s*\`(.+)\'\s*$/
563
567
 
564
- if false;
565
- elsif fn =~ /(.+)\:in\s*\`(.+)\'\s*$/
568
+ fl = $1
569
+ fn = $2
566
570
 
567
- fl = $1
568
- fn = $2
571
+ f = "#{fl}: #{rx}#{fn}"
572
+ elsif fn =~ /.*in\s*\`(.+)\'\s*$/
569
573
 
570
- f = "#{fl}: #{rx}#{fn}"
571
- elsif fn =~ /.*in\s*\`(.+)\'\s*$/
574
+ f = $1
575
+ else
572
576
 
573
- f = $1
574
- else
577
+ f = fn
578
+ end
575
579
 
576
- f = fn
577
- end
580
+ if param_list
578
581
 
579
- if param_list
582
+ sig = ''
580
583
 
581
- sig = ''
584
+ argv.each_with_index do |arg, index0|
582
585
 
583
- argv.each_with_index do |arg, index0|
586
+ n = param_list[index0]
584
587
 
585
- n = param_list[index0]
588
+ s = arg.to_s
589
+ s = "'#{s}'" if s.index(/[,\s]/)
586
590
 
587
- s = arg.to_s
588
- s = "'#{s}'" if s.index(/[,\s]/)
591
+ sig += ', ' unless sig.empty?
589
592
 
590
- sig += ', ' unless sig.empty?
593
+ sig += n ? "#{n} (#{arg.class})=#{s}" : s
594
+ end
595
+ else
591
596
 
592
- sig += n ? "#{n} (#{arg.class})=#{s}" : s
593
- end
594
- else
597
+ sig = argv.join(', ')
598
+ end
595
599
 
596
- sig = argv.join(', ')
597
- end
600
+ stmt = "#{f}(#{sig})"
598
601
 
599
- stmt = "#{f}(#{sig})"
602
+ self.log_raw prefix_provider, severity, stmt
603
+ end
600
604
 
601
- self.log_raw prefix_provider, severity, stmt
602
- end
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
- # Internal implementation method, not to be called by application code
605
- #
606
- # @!visibility private
607
- def self.log_raw prefix_provider, severity, message # :nodoc:
610
+ now = Time.now
608
611
 
609
- now = Time.now
612
+ srp = @@state.requires_prefix?
610
613
 
611
- srp = @@state.requires_prefix?
614
+ case srp
615
+ when false
612
616
 
613
- case srp
614
- when false
617
+ prf = nil
618
+ when true
615
619
 
616
- prf = nil
617
- when true
620
+ prf = '[' + prefix_provider.prefix(now, severity) + ']: '
621
+ when :parts
618
622
 
619
- prf = '[' + prefix_provider.prefix(now, severity) + ']: '
620
- when :parts
623
+ prf = prefix_provider.prefix_parts(now, severity)
624
+ else
621
625
 
622
- prf = prefix_provider.prefix_parts(now, severity)
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
- warn "invalid value '#{srp}' returned by #requires_prefix? of the Pantheios Core's state's service (which is of type #{@@state.service.class}"
628
+ prf = nil
629
+ end
626
630
 
627
- prf = nil
628
- end
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