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