pantheios-ruby 0.13.4 → 0.20.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42dd156fe607cf0712c3f8bf87a4b18d00b5876f
4
- data.tar.gz: 2fb2a26c90fb74f89b0d6ddf37e95ae26a1786f8
3
+ metadata.gz: 5f5bcc837f0b87b903fe88c0b5d1eb3f2c8193a3
4
+ data.tar.gz: 6e4acd4a1a86ae3df1f04d5ab506c1f0b0722666
5
5
  SHA512:
6
- metadata.gz: 3143dabf9f559f38711bc3f90cc849fa3b91e21f08373cfaf63d769e6f704d27197cf9d22f5d3b1108e83db388987c815b59cbca1de5642e9f987a3b61da2005
7
- data.tar.gz: c203a65311dca3d02517ed8e1ba34b3cf2137a19d8514788a6dcb216700a2a56b07bca0f972a9981cafffb39232082b52c5cc2721e7427191697b8f077626e67
6
+ metadata.gz: 5d7eff164a890518c3fabca3612d6f5810a554235831838e6a98c47562061924d37e09300e610de1cef8759c9c6ee582b695020b0fd6297c69e82802c9f814d2
7
+ data.tar.gz: 873c24a5b54e6711d498e06e0c20c335a81fc2f737c0fa1da634c8b5faa2767c6da49743611481ef6c9a446f39953255a500b3bb526854a2e02e1ef997fc285d
data/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ Pantheios.Ruby
2
+
3
+ Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the names of Pantheios or Pantheios.Ruby nor the names of the
17
+ copyright holder nor the names of its contributors may be used to endorse
18
+ or promote products derived from this software without specific prior written
19
+ permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
@@ -0,0 +1,5 @@
1
+ # **Pantheios.Ruby**
2
+ Pantheios, for Ruby
3
+
4
+ T.B.C.
5
+
@@ -0,0 +1,65 @@
1
+ # Pantheios.Ruby Example - **simple_logging**
2
+
3
+ ## Summary
4
+
5
+ Simple example supporting ```--help``` and ```--version```.
6
+
7
+ ## Source
8
+
9
+ ```ruby
10
+ #!/usr/bin/env ruby
11
+
12
+ $:.unshift File.join(File.dirname(__FILE__), *([ '..' ] * 1), 'lib')
13
+
14
+ # requires (0)
15
+
16
+ require 'pantheios/globals'
17
+
18
+ # globals
19
+
20
+ Pantheios::Globals.MAIN_THREAD_NAME = [ Thread.current, 'main' ]
21
+ Pantheios::Globals.PROCESS_NAME = :script_stem
22
+
23
+ # requires (1)
24
+
25
+ require 'pantheios'
26
+
27
+ # includes
28
+
29
+ include ::Pantheios
30
+
31
+ # constants
32
+
33
+ LEVELS = %i{ violation alert critical failure warning notice informational debug0 debug1 debug2 debug3 debug4 }
34
+
35
+ # main
36
+
37
+ LEVELS.each do |level|
38
+
39
+ log(level, "logging level #{level}")
40
+ end
41
+
42
+ # ############################## end of file ############################# #
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### No arguments
48
+
49
+ When executed gives the following output:
50
+
51
+ ```
52
+ [simple_logging, main, 2019-06-05 13:18:52.517479, Violation]: logging level violation
53
+ [simple_logging, main, 2019-06-05 13:18:52.517615, Alert]: logging level alert
54
+ [simple_logging, main, 2019-06-05 13:18:52.517653, Critical]: logging level critical
55
+ [simple_logging, main, 2019-06-05 13:18:52.517681, Failure]: logging level failure
56
+ [simple_logging, main, 2019-06-05 13:18:52.517709, Warning]: logging level warning
57
+ [simple_logging, main, 2019-06-05 13:18:52.517735, Notice]: logging level notice
58
+ [simple_logging, main, 2019-06-05 13:18:52.517763, Informational]: logging level informational
59
+ [simple_logging, main, 2019-06-05 13:18:52.517789, Debug-0]: logging level debug0
60
+ [simple_logging, main, 2019-06-05 13:18:52.517837, Debug-1]: logging level debug1
61
+ [simple_logging, main, 2019-06-05 13:18:52.517876, Debug-2]: logging level debug2
62
+ [simple_logging, main, 2019-06-05 13:18:52.517905, Debug-3]: logging level debug3
63
+ [simple_logging, main, 2019-06-05 13:18:52.517931, Debug-4]: logging level debug4
64
+ ```
65
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *([ '..' ] * 1), 'lib')
4
+
5
+ # requires (0)
6
+
7
+ require 'pantheios/globals'
8
+
9
+ # globals
10
+
11
+ Pantheios::Globals.MAIN_THREAD_NAME = [ Thread.current, 'main' ]
12
+ Pantheios::Globals.PROCESS_NAME = :script_stem
13
+
14
+ # requires (1)
15
+
16
+ require 'pantheios'
17
+
18
+ # includes
19
+
20
+ include ::Pantheios
21
+
22
+ # constants
23
+
24
+ LEVELS = %i{ violation alert critical failure warning notice informational debug0 debug1 debug2 debug3 debug4 }
25
+
26
+ # main
27
+
28
+ LEVELS.each do |level|
29
+
30
+ log(level, "logging level #{level}")
31
+ end
32
+
33
+ # ############################## end of file ############################# #
34
+
35
+
@@ -70,7 +70,7 @@ module Pantheios
70
70
  #
71
71
  # - prefix_elements
72
72
  # - process_id
73
- # - program_name
73
+ # - process_name
74
74
  # - severity_string severity
75
75
  # - thread_id
76
76
  # - timestamp t
@@ -160,7 +160,7 @@ module API
160
160
  # === Elements
161
161
  #
162
162
  # Elements can be one of:
163
- # - +:program_name+
163
+ # - +:process_name+
164
164
  # - +:process_id+
165
165
  # - +:severity+
166
166
  # - +:thread_id+
@@ -169,7 +169,7 @@ module API
169
169
  # This is called from +prefix+
170
170
  def prefix_elements
171
171
 
172
- [ :program_name, :thread_id, :timestamp, :severity ]
172
+ [ :process_name, :thread_id, :timestamp, :severity ]
173
173
  end
174
174
 
175
175
  # Obtains the process id
@@ -184,10 +184,10 @@ module API
184
184
  # Obtains the program name
185
185
  #
186
186
  # Unless overridden, returns the value provided by
187
- # +::Pantheios::Core::program_name+
188
- def program_name
187
+ # +::Pantheios::Core::process_name+
188
+ def process_name
189
189
 
190
- ::Pantheios::Core.program_name
190
+ ::Pantheios::Core.process_name
191
191
  end
192
192
 
193
193
  # Obtains the string corresponding to the severity
@@ -222,9 +222,9 @@ module API
222
222
  prefix_elements.map do |el|
223
223
 
224
224
  case el
225
- when :program_name
225
+ when :program_name, :process_name
226
226
 
227
- program_name
227
+ process_name
228
228
  when :process_id
229
229
 
230
230
  process_id
@@ -7,7 +7,7 @@
7
7
  # namespace module
8
8
  #
9
9
  # Created: 2nd April 2011
10
- # Updated: 6th January 2018
10
+ # Updated: 12th March 2018
11
11
  #
12
12
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
13
13
  #
@@ -71,8 +71,8 @@ module StockSeverityLevels
71
71
  :debug2 => [ 10, 'Debug-2' ],
72
72
  :debug3 => [ 11, 'Debug-3' ],
73
73
  :debug4 => [ 12, 'Debug-4' ],
74
- :trace => [ 13, 'Trace' ],
75
- :benchmark => [ 14, 'Benchmark' ],
74
+ :trace => [ 15, 'Trace' ],
75
+ :benchmark => [ 16, 'Benchmark' ],
76
76
  }
77
77
 
78
78
  def self.create_level_keys m
@@ -5,7 +5,7 @@
5
5
  # Purpose: The Pantheios.Ruby core (::Pantheios::Core)
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 23rd January 2018
8
+ # Updated: 5th September 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
@@ -51,6 +51,8 @@ require 'pantheios/application_layer/stock_severity_levels'
51
51
  require 'pantheios/services/simple_console_log_service'
52
52
 
53
53
  require 'pantheios/util/process_util'
54
+ require 'pantheios/util/reflection_util'
55
+ require 'pantheios/util/thread_util'
54
56
 
55
57
  =begin
56
58
  =end
@@ -132,8 +134,14 @@ module Core
132
134
 
133
135
  def set_service svc
134
136
 
137
+ raise ::ArgumentError, 'service instance may not be nil' if svc.nil?
138
+
135
139
  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 }
136
140
 
141
+ nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc
142
+
143
+ 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 } }
144
+
137
145
  r = []
138
146
  srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true
139
147
 
@@ -199,6 +207,70 @@ module Core
199
207
  # :nodoc:
200
208
  def self.core_init
201
209
 
210
+ # process-name
211
+
212
+ prg_nam = nil
213
+
214
+ case Pantheios::Globals.PROCESS_NAME
215
+ when nil
216
+
217
+ ;
218
+ when ::Symbol
219
+
220
+ prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME
221
+ when ::String
222
+
223
+ prg_nam = Pantheios::Globals.PROCESS_NAME.strip
224
+ prg_nam = nil if prg_name.empty?
225
+ else
226
+
227
+ warn "ignoring unsupported Globals.PROCESS_NAME type - '#{Pantheios::Globals.PROCESS_NAME.class}'"
228
+ end
229
+
230
+ @process_name = prg_nam if prg_nam
231
+
232
+
233
+ # main thread-name
234
+ #
235
+ # This is obtained from Pantheios::Globals.MAIN_THREAD_NAME, which
236
+ # may be either ::String or [ ::String, ::Thread ]
237
+
238
+ mt_th = nil
239
+ mt_nam = nil
240
+
241
+ case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME
242
+ when nil
243
+
244
+ ;
245
+ when ::Array
246
+
247
+ if pg_mtn.size != 2
248
+
249
+ warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE"
250
+ else
251
+
252
+ mt_th = pg_mtn[0]
253
+ mt_nam = pg_mtn[1]
254
+
255
+ if ::Thread === mt_nam
256
+
257
+ mt_th, mt_nam = mt_nam, mt_th
258
+ end
259
+ end
260
+ when ::String
261
+
262
+ mt_th = Thread.current
263
+ mt_nam = pg_mtn
264
+ else
265
+
266
+ warn "ignoring unsupported Globals.MAIN_THREAD_NAME type - '#{Pantheios::Globals.MAIN_THREAD_NAME.class}'"
267
+ end
268
+
269
+ ::Pantheios::Util::ThreadUtil.set_thread_name mt_th, mt_nam if mt_nam
270
+
271
+
272
+ # state (incl. default service)
273
+
202
274
  @@state = Internals_::State.new Internals_::DefaultDiscriminator.new
203
275
 
204
276
  self.set_default_service
@@ -209,14 +281,14 @@ module Core
209
281
 
210
282
  # determine which log service to initialise as the default
211
283
 
212
- (::Pantheios::Globals.INITIAL_SERVICE_INSTANCES || []).each do |inst|
284
+ ([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst|
213
285
 
214
286
  next unless inst
215
287
 
216
288
  return @@state.set_service inst
217
289
  end
218
290
 
219
- (::Pantheios::Globals.INITIAL_SERVICE_CLASSES || []).each do |cls|
291
+ ([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).each do |cls|
220
292
 
221
293
  inst = cls.new
222
294
 
@@ -307,18 +379,43 @@ module Core
307
379
  Process.pid
308
380
  end
309
381
 
310
- # Default implementation to obtain the program name
382
+ # Default implementation to obtain the process name
311
383
  #
312
384
  # * *Returns:*
313
385
  # The file stem of +$0+
314
386
  #
315
- # NOTE: this is implemented in terms of Process_Util.derive_process_name
316
- # and the result is cached
317
- def self.program_name
387
+ # NOTE: this is implemented in terms of
388
+ # +Process_Util.derive_process_name+ and the result is cached
389
+ def self.process_name
318
390
 
319
- @program_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0
391
+ @process_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0
320
392
  end
321
393
 
394
+ # [DEPRECATED] Use +process_name+
395
+ def self.program_name; self.process_name; end
396
+
397
+ # Sets the process name
398
+ #
399
+ # * *Parameters:*
400
+ # - +name+:: [String] The (new) process name. May be +nil+, in which
401
+ # case +process_name+ will obtain the process name from
402
+ # +Process_Util.derive_process_name+
403
+ #
404
+ # * *Returns:*
405
+ # The previous version
406
+ #
407
+ # NOTE: to reset the value, set to +nil+
408
+ def self.process_name= name
409
+
410
+ previous, @process_name = @process_name, name
411
+
412
+ previous
413
+ end
414
+
415
+ # [DEPRECATED] Use +process_name=+
416
+ def self.program_name= name; self.process_name = name; end
417
+
418
+ # Obtains a string form of the given severity
322
419
  def self.severity_string severity
323
420
 
324
421
  r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r
@@ -409,7 +506,7 @@ module Core
409
506
 
410
507
  if block_given?
411
508
 
412
- br = get_block_value_ &block
509
+ br = get_block_value_(&block)
413
510
 
414
511
  if ApplicationLayer::ParamNameList === br
415
512
 
@@ -430,20 +527,21 @@ module Core
430
527
  end
431
528
  end
432
529
 
530
+ fl = nil
531
+ rx = nil
532
+ fn = caller(call_depth + 1, 1)[0]
533
+
433
534
  case param_list
434
535
  when nil
435
536
  ;
436
537
  when ApplicationLayer::ParamNameList
437
- ;
538
+
539
+ warn "#{fn}: param_list must contain only strings or symbols" unless param_list.all? { |p| p.kind_of?(::String) || p.kind_of?(::Symbol) }
438
540
  else
439
541
 
440
- warn "param_list (#{param_list.class}) must be nil or an instance of #{ApplicationLayer::ParamNameList}" unless param_list
542
+ warn "#{fn}: param_list (#{param_list.class}) must be nil or an instance of #{ApplicationLayer::ParamNameList}" unless param_list
441
543
  end
442
544
 
443
- fl = nil
444
- rx = nil
445
- fn = caller(call_depth + 1, 1)[0]
446
-
447
545
  if ::Class === prefix_provider
448
546
 
449
547
  rx = "#{prefix_provider}::"
@@ -5,7 +5,7 @@
5
5
  # Purpose: The Pantheios.Ruby "globals" (::Pantheios::Globals)
6
6
  #
7
7
  # Created: 24th December 2017
8
- # Updated: 22nd January 2018
8
+ # Updated: 4th February 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
@@ -57,11 +57,24 @@ module Pantheios
57
57
  #
58
58
  # === Variables
59
59
  #
60
+ # * *MAIN_THREAD_NAME* A string specifying the main thread name, or an array
61
+ # containing a thread instance and a string specifying the thread and its
62
+ # name
63
+ #
64
+ # NOTE: This feature is subject to the initialising threads: if the string
65
+ # form is used then the first initialising thread of Pantheios.Ruby will
66
+ # be the named thread
67
+ #
60
68
  # * *HAS_CASCADED_INCLUDES* [boolean] Determines whether including
61
69
  # +::Pantheios+ also includes all relevant parts of subordinate
62
70
  # namespaces. See the documentation for the +::Pantheios+ namespace for
63
71
  # further details
64
72
  #
73
+ # * *PROCESS_NAME* A string specifying the process name, or one of the
74
+ # recognised symbols - :script, :script_basename, :script_dirname,
75
+ # :script_realpath, :script_stem - that directs inference of the process
76
+ # name. See +Pantheios::Util::ProcessUtil::derive_process_name+
77
+ #
65
78
  # * *SYNCHRONISED_SEVERITY_LOGGED* [boolean] Determines whether the core
66
79
  # protects the call to the underlying log-service's +severity_logged?+
67
80
  # with a mutex (which has a non-trivial cost).
@@ -70,8 +83,10 @@ module Globals
70
83
 
71
84
  module Internals_
72
85
 
73
- BOOLEAN_CLASSES = [ ::FalseClass, ::TrueClass ]
74
- TRUTHY_CLASSES = BOOLEAN_CLASSES + [ ::NilClass ]
86
+ BOOLEAN_CLASSES = [ ::FalseClass, ::TrueClass ]
87
+ TRUTHY_CLASSES = BOOLEAN_CLASSES + [ ::NilClass ]
88
+
89
+ PROCESS_NAME_CLASSES = [ ::Symbol, ::String ]
75
90
  end
76
91
 
77
92
  module Helpers_
@@ -117,6 +132,10 @@ module Globals
117
132
 
118
133
  Helpers_.cattr self, 'INITIAL_SERVICE_CLASSES', nil, nil
119
134
 
135
+ Helpers_.cattr self, 'MAIN_THREAD_NAME', [ ::Array, ::String ], nil
136
+
137
+ Helpers_.cattr self, 'PROCESS_NAME', Internals_::PROCESS_NAME_CLASSES, nil
138
+
120
139
  Helpers_.cattr self, 'SYNCHRONISED_SEVERITY_LOGGED', nil, true, boolean: true
121
140
 
122
141
  def self.included receiver