pantheios-ruby 0.13.4 → 0.20.3.1

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.
@@ -4,13 +4,41 @@ module Util
4
4
 
5
5
  module ProcessUtil
6
6
 
7
- def self.derive_process_name dollar0 = nil
7
+ #
8
+ # * *Options:*
9
+ # - +:style+:: (:script, :script_basename, :script_dirname,
10
+ # :script_realpath, :script_stem) directs the inference of the process
11
+ # name. If none specified, :script_stem is assumed
12
+ def self.derive_process_name dollar0 = nil, **options
8
13
 
9
- dollar0 ||= $0
14
+ dollar0 ||= $0
10
15
 
11
- bn = File.basename dollar0
16
+ style = options[:style] || :script_stem
12
17
 
13
- bn =~ /\.rb$/ ? $` : bn
18
+ case style
19
+ when :script
20
+
21
+ dollar0
22
+ when :script_basename
23
+
24
+ File.basename(dollar0)
25
+ when :script_dirname
26
+
27
+ File.basename(File.realpath(File.dirname(dollar0)))
28
+ when :script_realpath
29
+
30
+ File.realpath(File.dirname(dollar0))
31
+ when :script_stem
32
+
33
+ bn = File.basename(dollar0)
34
+
35
+ bn =~ /\.rb$/ ? $` : bn
36
+ else
37
+
38
+ warn "#{self.class}##{__method__}: ignoring unrecognised type/value for ':style': '#{style}' (#{style.class})"
39
+
40
+ dollar0
41
+ end
14
42
  end
15
43
 
16
44
  end # module ProcessUtil
@@ -0,0 +1,34 @@
1
+
2
+ module Pantheios
3
+ module Util
4
+
5
+ module ReflectionUtil
6
+
7
+ module ReflectionUtil_Constants
8
+
9
+ ROOT_CLASSES = [ ::Object, ::BasicObject ]
10
+ end
11
+
12
+ def self.non_root_classes o
13
+
14
+ return [] if o.nil?
15
+
16
+ return self.non_root_classes o.class unless ::Class === o
17
+
18
+ return [] if ReflectionUtil_Constants::ROOT_CLASSES.any? { |c| c == o }
19
+
20
+ s = o.superclass
21
+
22
+ return [ o ] if ::Object == s
23
+
24
+ [ o ] + self.non_root_classes(s)
25
+ end
26
+
27
+ end # module ProcessUtil
28
+
29
+ end # module Util
30
+ end # module Pantheios
31
+
32
+ # ############################## end of file ############################# #
33
+
34
+
@@ -5,13 +5,13 @@
5
5
  # Purpose: Version for Pantheios.Ruby library
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 23rd January 2018
8
+ # Updated: 5th June 2019
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2011-2019, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
50
50
  module Pantheios
51
51
 
52
52
  # Current version of the Pantheios.Ruby library
53
- VERSION = '0.13.4'
53
+ VERSION = '0.20.3.1'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -37,7 +37,9 @@ end
37
37
 
38
38
  Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:') do |r|
39
39
 
40
- at_0 = r.report("arguments (1-arg)") do
40
+ totals = []
41
+
42
+ totals << r.report("arguments (1-arg)") do
41
43
 
42
44
  for i in (0...N) do
43
45
 
@@ -45,7 +47,7 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
45
47
  end
46
48
  end
47
49
 
48
- bt_0 = r.report("blocks (1-arg)") do
50
+ totals << r.report("blocks (1-arg)") do
49
51
 
50
52
  for i in (0...N) do
51
53
 
@@ -53,7 +55,16 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
53
55
  end
54
56
  end
55
57
 
56
- at_1 = r.report("arguments (simple)") do
58
+ totals << r.report("args-if (1-arg)") do
59
+
60
+ for i in (0...N) do
61
+
62
+ log :notice, 'the cat in the hat.' if severity_logged? :notice
63
+ end
64
+ end
65
+
66
+
67
+ totals << r.report("arguments (simple)") do
57
68
 
58
69
  for i in (0...N) do
59
70
 
@@ -61,7 +72,7 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
61
72
  end
62
73
  end
63
74
 
64
- bt_1 = r.report("blocks (simple)") do
75
+ totals << r.report("blocks (simple)") do
65
76
 
66
77
  for i in (0...N) do
67
78
 
@@ -69,7 +80,16 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
69
80
  end
70
81
  end
71
82
 
72
- at_2 = r.report("arguments (complex)") do
83
+ totals << r.report("args-if (simple)") do
84
+
85
+ for i in (0...N) do
86
+
87
+ log :notice, 'the ', 'cat ', 'in ', 'the ', 'hat.' if severity_logged? :notice
88
+ end
89
+ end
90
+
91
+
92
+ totals << r.report("arguments (complex)") do
73
93
 
74
94
  cat = 'cat'
75
95
  hat = :hat
@@ -81,7 +101,7 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
81
101
  end
82
102
  end
83
103
 
84
- bt_2 = r.report("blocks (complex)") do
104
+ totals << r.report("blocks (complex)") do
85
105
 
86
106
  cat = 'cat'
87
107
  hat = :hat
@@ -93,7 +113,20 @@ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:')
93
113
  end
94
114
  end
95
115
 
96
- [ at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2, (at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2) / 2 ]
116
+ totals << r.report("args-if (complex)") do
117
+
118
+ cat = 'cat'
119
+ hat = :hat
120
+ t = Time.now
121
+
122
+ for i in (0...N) do
123
+
124
+ log :notice, "the #{cat} in the #{hat} (#{t})" if severity_logged? :notice
125
+ end
126
+ end
127
+
128
+
129
+ [ totals.inject(:+), totals.inject(:+) / totals.size ]
97
130
  end
98
131
 
99
132
 
File without changes
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/scratch/log_rolling_by_period_daily.rb
5
+ #
6
+ # Purpose: Tests the log-rolling functionality of SimpleFileLogService
7
+ #
8
+ # Created: 4th February 2018
9
+ # Updated: 4th February 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios/globals'
20
+ require 'pantheios/services/simple_file_log_service'
21
+
22
+ log_path_base = File.join(File.dirname(__FILE__), 'log_files', 'log_rolling_by_period_daily')
23
+
24
+ Pantheios::Globals.INITIAL_SERVICE_INSTANCES = Pantheios::Services::SimpleFileLogService.new log_path_base, roll_period: :daily
25
+
26
+ require 'pantheios'
27
+
28
+ include Pantheios
29
+
30
+ log :notice, 'program starting ...'
31
+
32
+ log(:notice) { 'program started' }
33
+
34
+ (0..1000).each do |n|
35
+
36
+ log :informational, "increment #{n}: '#{'*' * 10 * n}'"
37
+
38
+ sleep 100
39
+ end
40
+
41
+ at_exit { log :notice, 'program ending ...' }
42
+
43
+
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/scratch/log_rolling_by_size_and_depth.rb
5
+ #
6
+ # Purpose: Tests the log-rolling functionality of SimpleFileLogService
7
+ #
8
+ # Created: 4th February 2018
9
+ # Updated: 4th February 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios/globals'
20
+ require 'pantheios/services/simple_file_log_service'
21
+
22
+ log_path_base = File.join(File.dirname(__FILE__), 'log_files', 'log_rolling_by_size_and_depth')
23
+
24
+ Pantheios::Globals.INITIAL_SERVICE_INSTANCES = Pantheios::Services::SimpleFileLogService.new log_path_base, roll_size: [ 1000, 10 ]
25
+
26
+ require 'pantheios'
27
+
28
+ include Pantheios
29
+
30
+ log :notice, 'program starting ...'
31
+
32
+ log(:notice) { 'program started' }
33
+
34
+ (0..1000).each do |n|
35
+
36
+ log :informational, "increment #{n}: '#{'*' * 10 * n}'"
37
+
38
+ sleep 1
39
+ end
40
+
41
+ at_exit { log :notice, 'program ending ...' }
42
+
43
+
@@ -6,7 +6,7 @@
6
6
  # Purpose: COMPLETE_ME
7
7
  #
8
8
  # Created: 22nd January 2018
9
- # Updated: 22nd January 2018
9
+ # Updated: 5th February 2018
10
10
  #
11
11
  # Author: Matthew Wilson
12
12
  #
@@ -16,6 +16,12 @@
16
16
 
17
17
  $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
18
 
19
+ require 'pantheios/globals'
20
+
21
+ Pantheios::Globals.MAIN_THREAD_NAME = [ Thread.current, 'main' ]
22
+ Pantheios::Globals.PROCESS_NAME = :script_stem
23
+
24
+
19
25
  require 'pantheios'
20
26
 
21
27
  include Pantheios
@@ -66,3 +72,4 @@ puts
66
72
 
67
73
  h 'lmnop', :q, :rst
68
74
 
75
+
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/scratch/multiplexing_log_service.rb
5
+ #
6
+ # Purpose: COMPLETE_ME
7
+ #
8
+ # Created: 7th February 2018
9
+ # Updated: 7th February 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios'
20
+ require 'pantheios/application_layer/stock_severity_levels'
21
+ require 'pantheios/services'
22
+
23
+ $num_BLS_sls = 0
24
+ $num_ELS_sls = 0
25
+
26
+ class BenchmarkLogService
27
+
28
+ def severity_logged? severity
29
+
30
+ $num_BLS_sls += 1
31
+
32
+ (0..100).each { |n| n ** n }
33
+
34
+ :benchmark == severity.to_s.to_sym
35
+ end
36
+
37
+ def log sev, t, pref, msg
38
+
39
+ puts "BENCHMARK: #{pref}#{msg}\n"
40
+ end
41
+ end
42
+
43
+ class EventLogService
44
+
45
+ def severity_logged? severity
46
+
47
+ $num_ELS_sls += 1
48
+
49
+ case severity.to_s.to_sym
50
+ when :notice, :warning, :failure, :critical, :alert, :violation
51
+
52
+ true
53
+ when :warn, :error, :emergency
54
+
55
+ true
56
+ else
57
+
58
+ false
59
+ end
60
+ end
61
+
62
+ def log sev, t, pref, msg
63
+
64
+ puts "EVENTLOG: #{pref}#{msg}\n"
65
+ end
66
+ end
67
+
68
+ scls = Pantheios::Services::SimpleConsoleLogService.new
69
+
70
+ def scls.severity_logged? severity; ![ :benchmark, :trace, :violation ].include? severity; end
71
+
72
+ services = [
73
+
74
+ BenchmarkLogService.new,
75
+ EventLogService.new,
76
+ scls,
77
+ ]
78
+
79
+ lcm = :none
80
+ #lcm = :thread_fixed
81
+ #lcm = :process_fixed
82
+ unsync = false
83
+ #unsync = true
84
+
85
+ Pantheios::Core.set_service Pantheios::Services::MultiplexingLogService.new(services, level_cache_mode: lcm, unsyc_process_lcm: unsync)
86
+
87
+ include Pantheios
88
+
89
+ t_b = Time.now
90
+
91
+ log :benchmark, 'statement at benchmark'
92
+ (0..100000).each { log :trace, 'statement at trace' }
93
+ log :debug4, 'statement at debug-4'
94
+ log :debug3, 'statement at debug-3'
95
+ log :debug2, 'statement at debug-2'
96
+ log :debug1, 'statement at debug-1'
97
+ log :debug0, 'statement at debug-0'
98
+ log :informational, 'statement at informational'
99
+ log :notice, 'statement at notice'
100
+ log :warning, 'statement at warning'
101
+ log :failure, 'statement at failure'
102
+ log :critical, 'statement at critical'
103
+ log :alert, 'statement at alert'
104
+ log :violation, 'statement at violation'
105
+
106
+ t_a = Time.now
107
+
108
+ $stderr.puts "mode= :#{lcm}; t=#{t_a - t_b}; #BLS=#{$num_BLS_sls}; #ELS=#{$num_ELS_sls}"
109
+
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/core'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_Core_set_process_name < Test::Unit::TestCase
12
+
13
+ Core = ::Pantheios::Core
14
+
15
+ def test_derive_process_name_obtains_the_same_results_but_different_instances
16
+
17
+ begin
18
+
19
+ Core.process_name = nil
20
+
21
+ n_1 = Core.process_name
22
+ n_2 = Core.process_name
23
+
24
+ assert_equal n_1, n_2
25
+ assert_same n_1, n_2
26
+
27
+
28
+ Core.process_name = nil
29
+
30
+ n_3 = Core.process_name
31
+
32
+ assert_equal n_1, n_3
33
+ assert_not_same n_1, n_3
34
+
35
+ ensure
36
+
37
+ Core.process_name = nil
38
+ end
39
+ end
40
+
41
+ def test_derive_process_name_accepts_custom_value
42
+
43
+ begin
44
+
45
+ Core.process_name = 'abc'
46
+
47
+ assert_equal 'abc', Core.process_name
48
+ ensure
49
+
50
+ Core.process_name = nil
51
+ end
52
+ end
53
+ end
54
+