pantheios-ruby 0.22.0.2 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/AUTHORS.md +21 -0
- data/CHANGES.md +337 -0
- data/CONTRIBUTING.md +36 -0
- data/EXAMPLES.md +11 -0
- data/FAQ.md +28 -0
- data/INSTALL.md +43 -0
- data/LICENSE +21 -20
- data/NEWS.md +65 -0
- data/README.md +134 -2
- data/Rakefile +21 -0
- data/SECURITY.md +23 -0
- data/TODO.md +29 -0
- data/examples/coloured_console_log_service.rb +1 -1
- data/examples/multiple_modules.md +1 -1
- data/examples/multiple_modules.rb +36 -36
- data/examples/simple_logging.md +1 -1
- data/examples/simple_logging.rb +1 -1
- data/examples/threshold_front_end.rb +1 -1
- data/lib/pantheios/api.rb +156 -155
- data/lib/pantheios/application_layer/param_name_list.rb +1 -0
- data/lib/pantheios/application_layer/stock_severity_levels.rb +110 -111
- data/lib/pantheios/application_layer.rb +6 -5
- data/lib/pantheios/core.rb +416 -415
- data/lib/pantheios/front_ends/threshold_front_end.rb +81 -81
- data/lib/pantheios/globals.rb +45 -45
- data/lib/pantheios/services/coloured_console_log_service.rb +96 -96
- data/lib/pantheios/services/common/console.rb +58 -57
- data/lib/pantheios/services/multiplexing_log_service.rb +151 -150
- data/lib/pantheios/services/null_log_service.rb +11 -11
- data/lib/pantheios/services/simple_console_log_service.rb +20 -20
- data/lib/pantheios/services/simple_file_log_service.rb +112 -113
- data/lib/pantheios/services/standard_log_service_adapter.rb +119 -119
- data/lib/pantheios/services.rb +1 -0
- data/lib/pantheios/util/process_util.rb +25 -24
- data/lib/pantheios/util/reflection_util.rb +14 -13
- data/lib/pantheios/util/thread_util.rb +50 -49
- data/lib/pantheios/util/version_util.rb +34 -33
- data/lib/pantheios/util.rb +1 -0
- data/lib/pantheios/version.rb +19 -19
- data/lib/pantheios.rb +12 -12
- data/test/performance/test_perf_simple_statements.rb +58 -58
- data/test/performance/test_perf_trace_variants.rb +43 -57
- data/test/scratch/log_rolling_by_period_daily.rb +3 -3
- data/test/scratch/log_rolling_by_size_and_depth.rb +3 -3
- data/test/scratch/log_using_blocks.rb +12 -12
- data/test/scratch/multiplexing_log_service.rb +32 -32
- data/test/unit/application_layer/tc_param_name_list.rb +13 -13
- data/test/unit/application_layer/tc_stock_severity_levels.rb +102 -102
- data/test/unit/core/tc_core_1.rb +24 -24
- data/test/unit/front_ends/tc_threshold_front_end.rb +65 -65
- data/test/unit/services/tc_multiplexing_log_service.rb +79 -79
- data/test/unit/services/tc_null_log_service.rb +42 -42
- data/test/unit/services/tc_simple_console_log_service.rb +70 -70
- data/test/unit/services/tc_simple_file_log_service.rb +146 -146
- data/test/unit/services/tc_standard_log_service_adapter.rb +94 -96
- data/test/unit/util/tc_process_util.rb +6 -6
- data/test/unit/util/tc_reflection_util.rb +20 -20
- data/test/unit/util/tc_thread_util.rb +46 -46
- data/test/unit/util/tc_version_util.rb +47 -47
- metadata +33 -12
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
module Internals_ # :nodoc: all
|
|
71
|
+
end # module Constants_
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
# @!visibility private
|
|
74
|
+
module Internals_ # :nodoc: all
|
|
78
75
|
|
|
79
|
-
|
|
76
|
+
# @!visibility private
|
|
77
|
+
class DefaultDiscriminator # :nodoc:
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
def severity_logged? severity
|
|
82
80
|
|
|
83
|
-
|
|
81
|
+
return true if $DEBUG
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
v_sev = levels[severity] if ::Symbol === severity
|
|
83
|
+
levels = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
|
87
84
|
|
|
88
|
-
|
|
85
|
+
v_info = levels[:informational]
|
|
86
|
+
v_sev = levels[severity] if ::Symbol === severity
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|
|
88
|
+
return false if v_sev > v_info
|
|
93
89
|
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
true
|
|
91
|
+
end
|
|
92
|
+
end
|
|
96
93
|
|
|
97
|
-
|
|
94
|
+
# @!visibility private
|
|
95
|
+
class State # :nodoc:
|
|
98
96
|
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
+
def set_front_end fe
|
|
109
107
|
|
|
110
|
-
|
|
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
|
-
|
|
110
|
+
r = nil
|
|
113
111
|
|
|
114
|
-
|
|
112
|
+
fe ||= @default_fe
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
end
|
|
114
|
+
@mx_service.synchronize do
|
|
118
115
|
|
|
119
|
-
|
|
116
|
+
r, @front_end = @front_end, fe
|
|
117
|
+
end
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
end
|
|
119
|
+
r = nil if r.object_id == @default_fe.object_id
|
|
123
120
|
|
|
124
|
-
|
|
121
|
+
return r
|
|
122
|
+
end
|
|
125
123
|
|
|
126
|
-
|
|
124
|
+
def set_back_end be
|
|
127
125
|
|
|
128
|
-
|
|
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
|
-
|
|
128
|
+
r = nil
|
|
129
|
+
srp = be.respond_to?(:requires_prefix?) ? be.requires_prefix? : true
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
end
|
|
131
|
+
@mx_service.synchronize do
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
r, @back_end, @requires_prefix = @back_end, be, srp
|
|
134
|
+
end
|
|
138
135
|
|
|
139
|
-
|
|
136
|
+
return r
|
|
137
|
+
end
|
|
140
138
|
|
|
141
|
-
|
|
139
|
+
def set_service svc
|
|
142
140
|
|
|
143
|
-
|
|
141
|
+
raise ::ArgumentError, 'service instance may not be nil' if svc.nil?
|
|
144
142
|
|
|
145
|
-
|
|
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
|
-
|
|
145
|
+
nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc
|
|
148
146
|
|
|
149
|
-
|
|
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
|
-
|
|
149
|
+
r = []
|
|
150
|
+
srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
|
|
153
151
|
|
|
154
|
-
|
|
155
|
-
r << @back_end
|
|
152
|
+
@mx_service.synchronize do
|
|
156
153
|
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
r << @front_end
|
|
155
|
+
r << @back_end
|
|
159
156
|
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
@front_end, @back_end, @requires_prefix = svc, svc, srp
|
|
158
|
+
end
|
|
162
159
|
|
|
163
|
-
|
|
160
|
+
return r
|
|
161
|
+
end
|
|
164
162
|
|
|
165
|
-
|
|
163
|
+
if ::Pantheios::Globals.SYNCHRONISED_SEVERITY_LOGGED?
|
|
166
164
|
|
|
167
|
-
|
|
165
|
+
def severity_logged? severity
|
|
168
166
|
|
|
169
|
-
|
|
167
|
+
@mx_service.synchronize do
|
|
170
168
|
|
|
171
|
-
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
else
|
|
169
|
+
return nil unless @front_end
|
|
175
170
|
|
|
176
|
-
|
|
171
|
+
@front_end.severity_logged? severity
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
else
|
|
177
175
|
|
|
178
|
-
|
|
179
|
-
end
|
|
180
|
-
end
|
|
176
|
+
def severity_logged? severity
|
|
181
177
|
|
|
182
|
-
|
|
178
|
+
return @front_end.severity_logged? severity
|
|
179
|
+
end
|
|
180
|
+
end
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
def log
|
|
185
183
|
|
|
186
|
-
|
|
184
|
+
end
|
|
187
185
|
|
|
188
|
-
|
|
186
|
+
def discriminator
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
@mx_service.synchronize do
|
|
191
189
|
|
|
192
|
-
|
|
193
|
-
end
|
|
190
|
+
if @service && @service.respond_to?(:severity_logged?)
|
|
194
191
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
end
|
|
192
|
+
return @service
|
|
193
|
+
end
|
|
198
194
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
207
|
-
|
|
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
|
-
|
|
210
|
-
|
|
206
|
+
# @!visibility private
|
|
207
|
+
def self.included receiver # :nodoc:
|
|
211
208
|
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
abort "Attempt to include #{self} into #{receiver}. This is not allowed"
|
|
210
|
+
end
|
|
214
211
|
|
|
215
|
-
|
|
212
|
+
# @!visibility private
|
|
213
|
+
def self.core_init # :nodoc:
|
|
216
214
|
|
|
217
|
-
|
|
215
|
+
# process-name
|
|
218
216
|
|
|
219
|
-
|
|
220
|
-
when nil
|
|
217
|
+
prg_nam = nil
|
|
221
218
|
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
case Pantheios::Globals.PROCESS_NAME
|
|
220
|
+
when nil
|
|
224
221
|
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
;
|
|
223
|
+
when ::Symbol
|
|
227
224
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
else
|
|
225
|
+
prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME
|
|
226
|
+
when ::String
|
|
231
227
|
|
|
232
|
-
|
|
233
|
-
|
|
228
|
+
prg_nam = Pantheios::Globals.PROCESS_NAME.strip
|
|
229
|
+
prg_nam = nil if prg_name.empty?
|
|
230
|
+
else
|
|
234
231
|
|
|
235
|
-
|
|
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
|
-
|
|
244
|
-
|
|
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
|
-
|
|
247
|
-
|
|
243
|
+
mt_th = nil
|
|
244
|
+
mt_nam = nil
|
|
248
245
|
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME
|
|
247
|
+
when nil
|
|
251
248
|
|
|
252
|
-
|
|
249
|
+
;
|
|
250
|
+
when ::Array
|
|
253
251
|
|
|
254
|
-
|
|
255
|
-
else
|
|
252
|
+
if pg_mtn.size != 2
|
|
256
253
|
|
|
257
|
-
|
|
258
|
-
|
|
254
|
+
warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE"
|
|
255
|
+
else
|
|
259
256
|
|
|
260
|
-
|
|
257
|
+
mt_th = pg_mtn[0]
|
|
258
|
+
mt_nam = pg_mtn[1]
|
|
261
259
|
|
|
262
|
-
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
when ::String
|
|
260
|
+
if ::Thread === mt_nam
|
|
266
261
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
262
|
+
mt_th, mt_nam = mt_nam, mt_th
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
when ::String
|
|
270
266
|
|
|
271
|
-
|
|
272
|
-
|
|
267
|
+
mt_th = Thread.current
|
|
268
|
+
mt_nam = pg_mtn
|
|
269
|
+
else
|
|
273
270
|
|
|
274
|
-
|
|
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
|
-
|
|
277
|
+
# state (incl. default service)
|
|
280
278
|
|
|
281
|
-
|
|
282
|
-
end
|
|
279
|
+
@@state = Internals_::State.new Internals_::DefaultDiscriminator.new
|
|
283
280
|
|
|
284
|
-
|
|
285
|
-
|
|
281
|
+
self.set_default_service
|
|
282
|
+
end
|
|
286
283
|
|
|
287
|
-
|
|
284
|
+
# @!visibility private
|
|
285
|
+
def self.set_default_service **options # :nodoc:
|
|
288
286
|
|
|
289
|
-
|
|
287
|
+
# determine which log service to initialise as the default
|
|
290
288
|
|
|
291
|
-
|
|
289
|
+
([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst|
|
|
292
290
|
|
|
293
|
-
|
|
294
|
-
end
|
|
291
|
+
next unless inst
|
|
295
292
|
|
|
296
|
-
|
|
293
|
+
return @@state.set_service inst
|
|
294
|
+
end
|
|
297
295
|
|
|
298
|
-
|
|
296
|
+
([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).each do |cls|
|
|
299
297
|
|
|
300
|
-
|
|
301
|
-
end
|
|
298
|
+
inst = cls.new
|
|
302
299
|
|
|
303
|
-
|
|
304
|
-
|
|
300
|
+
return @@state.set_service inst
|
|
301
|
+
end
|
|
305
302
|
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
|
|
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
|
-
|
|
336
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
427
|
+
r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r
|
|
427
428
|
|
|
428
|
-
|
|
429
|
-
|
|
429
|
+
severity.to_s
|
|
430
|
+
end
|
|
430
431
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
439
|
+
t = Thread.current
|
|
439
440
|
|
|
440
|
-
|
|
441
|
+
return t.thread_name if t.respond_to? :thread_name
|
|
441
442
|
|
|
442
|
-
|
|
443
|
-
|
|
443
|
+
t.object_id
|
|
444
|
+
end
|
|
444
445
|
|
|
445
|
-
|
|
446
|
+
def self.timestamp_format
|
|
446
447
|
|
|
447
|
-
|
|
448
|
-
|
|
448
|
+
'%Y-%m-%d %H:%M:%S.%6N'
|
|
449
|
+
end
|
|
449
450
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
463
|
+
fmt ||= self.timestamp_format
|
|
463
464
|
|
|
464
|
-
|
|
465
|
-
|
|
465
|
+
t.strftime fmt
|
|
466
|
+
end
|
|
466
467
|
|
|
467
468
|
|
|
468
469
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
475
|
-
|
|
475
|
+
case block.arity
|
|
476
|
+
when 0
|
|
476
477
|
|
|
477
|
-
|
|
478
|
-
|
|
478
|
+
yield
|
|
479
|
+
when 1
|
|
479
480
|
|
|
480
|
-
|
|
481
|
-
|
|
481
|
+
yield severity
|
|
482
|
+
when 2
|
|
482
483
|
|
|
483
|
-
|
|
484
|
-
|
|
484
|
+
yield severity, argv
|
|
485
|
+
when 3
|
|
485
486
|
|
|
486
|
-
|
|
487
|
-
|
|
487
|
+
yield severity, argv, self
|
|
488
|
+
else
|
|
488
489
|
|
|
489
|
-
|
|
490
|
+
warn 'too many parameters in logging block'
|
|
490
491
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
492
|
+
yield severity, argv, self
|
|
493
|
+
end
|
|
494
|
+
end
|
|
494
495
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
|
|
501
|
+
argv << get_block_value_(&block) if block_given?
|
|
501
502
|
|
|
502
|
-
|
|
503
|
-
|
|
503
|
+
self.log_raw prefix_provider, severity, argv.join
|
|
504
|
+
end
|
|
504
505
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
511
|
+
unless param_list
|
|
511
512
|
|
|
512
|
-
|
|
513
|
+
if ApplicationLayer::ParamNameList === argv[0]
|
|
513
514
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
515
|
+
param_list = argv.shift
|
|
516
|
+
end
|
|
517
|
+
end
|
|
517
518
|
|
|
518
|
-
|
|
519
|
+
if block_given?
|
|
519
520
|
|
|
520
|
-
|
|
521
|
+
br = get_block_value_(&block)
|
|
521
522
|
|
|
522
|
-
|
|
523
|
+
if ApplicationLayer::ParamNameList === br
|
|
523
524
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
param_list = br
|
|
526
|
+
else
|
|
527
|
+
if ::Array === br
|
|
527
528
|
|
|
528
|
-
|
|
529
|
+
if ApplicationLayer::ParamNameList === br[0]
|
|
529
530
|
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
param_list = br.shift
|
|
532
|
+
end
|
|
532
533
|
|
|
533
|
-
|
|
534
|
-
|
|
534
|
+
argv += br
|
|
535
|
+
else
|
|
535
536
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
argv << br
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
end
|
|
540
541
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
542
|
+
fl = nil
|
|
543
|
+
rx = nil
|
|
544
|
+
fn = caller(call_depth + 1, 1)[0]
|
|
544
545
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
546
|
+
case param_list
|
|
547
|
+
when nil
|
|
548
|
+
;
|
|
549
|
+
when ApplicationLayer::ParamNameList
|
|
549
550
|
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
554
|
-
|
|
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
|
-
|
|
557
|
+
if ::Class === prefix_provider
|
|
557
558
|
|
|
558
|
-
|
|
559
|
-
|
|
559
|
+
rx = "#{prefix_provider}::"
|
|
560
|
+
else
|
|
560
561
|
|
|
561
|
-
|
|
562
|
-
|
|
562
|
+
rx = "#{prefix_provider.class}#"
|
|
563
|
+
end
|
|
563
564
|
|
|
564
|
-
|
|
565
|
-
|
|
565
|
+
if false;
|
|
566
|
+
elsif fn =~ /(.+)\:in\s*\`(.+)\'\s*$/
|
|
566
567
|
|
|
567
|
-
|
|
568
|
-
|
|
568
|
+
fl = $1
|
|
569
|
+
fn = $2
|
|
569
570
|
|
|
570
|
-
|
|
571
|
-
|
|
571
|
+
f = "#{fl}: #{rx}#{fn}"
|
|
572
|
+
elsif fn =~ /.*in\s*\`(.+)\'\s*$/
|
|
572
573
|
|
|
573
|
-
|
|
574
|
-
|
|
574
|
+
f = $1
|
|
575
|
+
else
|
|
575
576
|
|
|
576
|
-
|
|
577
|
-
|
|
577
|
+
f = fn
|
|
578
|
+
end
|
|
578
579
|
|
|
579
|
-
|
|
580
|
+
if param_list
|
|
580
581
|
|
|
581
|
-
|
|
582
|
+
sig = ''
|
|
582
583
|
|
|
583
|
-
|
|
584
|
+
argv.each_with_index do |arg, index0|
|
|
584
585
|
|
|
585
|
-
|
|
586
|
+
n = param_list[index0]
|
|
586
587
|
|
|
587
|
-
|
|
588
|
-
|
|
588
|
+
s = arg.to_s
|
|
589
|
+
s = "'#{s}'" if s.index(/[,\s]/)
|
|
589
590
|
|
|
590
|
-
|
|
591
|
+
sig += ', ' unless sig.empty?
|
|
591
592
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
sig += n ? "#{n} (#{arg.class})=#{s}" : s
|
|
594
|
+
end
|
|
595
|
+
else
|
|
595
596
|
|
|
596
|
-
|
|
597
|
-
|
|
597
|
+
sig = argv.join(', ')
|
|
598
|
+
end
|
|
598
599
|
|
|
599
|
-
|
|
600
|
+
stmt = "#{f}(#{sig})"
|
|
600
601
|
|
|
601
|
-
|
|
602
|
-
|
|
602
|
+
self.log_raw prefix_provider, severity, stmt
|
|
603
|
+
end
|
|
603
604
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
-
|
|
610
|
+
now = Time.now
|
|
610
611
|
|
|
611
|
-
|
|
612
|
+
srp = @@state.requires_prefix?
|
|
612
613
|
|
|
613
|
-
|
|
614
|
-
|
|
614
|
+
case srp
|
|
615
|
+
when false
|
|
615
616
|
|
|
616
|
-
|
|
617
|
-
|
|
617
|
+
prf = nil
|
|
618
|
+
when true
|
|
618
619
|
|
|
619
|
-
|
|
620
|
-
|
|
620
|
+
prf = '[' + prefix_provider.prefix(now, severity) + ']: '
|
|
621
|
+
when :parts
|
|
621
622
|
|
|
622
|
-
|
|
623
|
-
|
|
623
|
+
prf = prefix_provider.prefix_parts(now, severity)
|
|
624
|
+
else
|
|
624
625
|
|
|
625
|
-
|
|
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
|
-
|
|
628
|
-
|
|
628
|
+
prf = nil
|
|
629
|
+
end
|
|
629
630
|
|
|
630
|
-
|
|
631
|
-
|
|
631
|
+
@@state.back_end.log severity, now, prf, message
|
|
632
|
+
end
|
|
632
633
|
|
|
633
634
|
end # Core
|
|
634
635
|
end # Pantheios
|