pantheios-ruby 0.20.3.1 → 0.21.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f5bcc837f0b87b903fe88c0b5d1eb3f2c8193a3
4
- data.tar.gz: 6e4acd4a1a86ae3df1f04d5ab506c1f0b0722666
3
+ metadata.gz: beccaa832a0515a050313c91e674a3804ffe4ac5
4
+ data.tar.gz: 2d1e8e82b8f7999578c9898afc94730e86e165d2
5
5
  SHA512:
6
- metadata.gz: 5d7eff164a890518c3fabca3612d6f5810a554235831838e6a98c47562061924d37e09300e610de1cef8759c9c6ee582b695020b0fd6297c69e82802c9f814d2
7
- data.tar.gz: 873c24a5b54e6711d498e06e0c20c335a81fc2f737c0fa1da634c8b5faa2767c6da49743611481ef6c9a446f39953255a500b3bb526854a2e02e1ef997fc285d
6
+ metadata.gz: 06cfa816a8c31242ea15e6673064c136ccf7b1457f8ed399c165426c2515879c3f3d465aae57f302c3880bcee8b6ef7101e95c93f0526a5b0c9c6eeb521453c1
7
+ data.tar.gz: 3887176f2effa59a70304a4c8b5c8da013bf122f9d8882042955767c700b747ceea39d859d0351430fecc08ec32fabfc73f09513cf0d50c3367e22cbe58ef188
@@ -0,0 +1,204 @@
1
+ # Pantheios.Ruby Example - **multiple_modules**
2
+
3
+ ## Summary
4
+
5
+ Example showing application of Pantheios into multiple modules and
6
+ suppression of arbitrary severity levels specified as command line
7
+ arguments
8
+
9
+ ## Source
10
+
11
+ ```ruby
12
+ #!/usr/bin/env ruby
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), *([ '..' ] * 1), 'lib')
15
+
16
+ # ######################################
17
+ # requires
18
+
19
+ require 'pantheios'
20
+
21
+ # ######################################
22
+ # modules
23
+
24
+ module Organisation
25
+
26
+ module Helpers
27
+
28
+ include ::Pantheios
29
+
30
+ def with_trace
31
+
32
+ trace
33
+ end
34
+
35
+ def with_debug0; log(:debug0); end
36
+ def with_debug1; log(:debug1); end
37
+ def with_informational; log(:informational); end
38
+ def with_notice; log(:notice); end
39
+ def with_warning; log(:warning); end
40
+ def with_failure; log(:failure); end
41
+ def with_critical; log(:critical); end
42
+ def with_alert; log(:alert); end
43
+
44
+ def helper1
45
+
46
+ trace
47
+
48
+ with_debug0
49
+
50
+ with_notice
51
+ end
52
+
53
+ end # module Helpers
54
+
55
+ class OrgClass
56
+
57
+ include Helpers
58
+ include ::Pantheios
59
+
60
+ def initialize()
61
+
62
+ trace
63
+
64
+ log(:debug2) { 'initialised instance of OrgClass' }
65
+
66
+ helper1
67
+ end
68
+
69
+ end # class OrgClas
70
+
71
+ end # module Organisation
72
+
73
+ # ######################################
74
+ # includes
75
+
76
+ include ::Organisation::Helpers
77
+
78
+ include ::Pantheios
79
+
80
+ # ######################################
81
+ # constants
82
+
83
+ SUPPRESSED_SEVERITIES = %i{
84
+
85
+
86
+ }
87
+
88
+ # ######################################
89
+ # diagnostics
90
+
91
+ def detect_suppression argv
92
+
93
+ argv.each do |arg|
94
+
95
+ SUPPRESSED_SEVERITIES << arg.to_sym
96
+ end
97
+ end
98
+
99
+ class FrontEnd
100
+
101
+ def severity_logged? severity
102
+
103
+ case severity
104
+ when ::Symbol
105
+
106
+ !SUPPRESSED_SEVERITIES.include?(severity)
107
+ else
108
+
109
+ true
110
+ end
111
+ end
112
+ end
113
+
114
+ Pantheios::Core.set_front_end FrontEnd.new
115
+
116
+ # ######################################
117
+ # main
118
+
119
+ detect_suppression ARGV
120
+
121
+ log(:some_level)
122
+
123
+ log(:notice, 'starting up')
124
+
125
+ puts "Suppressed severities: #{SUPPRESSED_SEVERITIES}"
126
+
127
+ log(:info) { "Calling helpers" }
128
+
129
+ with_trace
130
+
131
+ with_debug0
132
+ with_debug1
133
+ helper1
134
+ with_critical
135
+ with_alert
136
+
137
+ log(:info) { "Creating instance of OrgClass" }
138
+
139
+ oc = Organisation::OrgClass.new
140
+
141
+ # ############################## end of file ############################# #
142
+
143
+ ```
144
+
145
+
146
+ ## Usage
147
+
148
+ ### No arguments
149
+
150
+ When executed as follows
151
+
152
+ ```
153
+ $ ./examples/multiple_modules.rb
154
+ ```
155
+
156
+ it gives the following output:
157
+
158
+ ```
159
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.853720, some_level]:
160
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.853882, Notice]: starting up
161
+ Suppressed severities: []
162
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.853971, Informational]: Calling helpers
163
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854134, Trace]: ./examples/multiple_modules.rb:21: Object#with_trace()
164
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854200, Debug-0]:
165
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854255, Debug-1]:
166
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854333, Trace]: ./examples/multiple_modules.rb:35: Object#helper1()
167
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854386, Debug-0]:
168
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854522, Notice]:
169
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854582, Critical]:
170
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854631, Alert]:
171
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854684, Informational]: Creating instance of OrgClass
172
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854772, Trace]: ./examples/multiple_modules.rb:51: Organisation::OrgClass#initialize()
173
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854852, Debug-2]: initialised instance of OrgClass
174
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854930, Trace]: ./examples/multiple_modules.rb:35: Organisation::OrgClass#helper1()
175
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.854985, Debug-0]:
176
+ [multiple_modules, 70123884951220, 2020-06-03 20:30:15.855035, Notice]:
177
+ ```
178
+
179
+ ### Some named suppressed levels
180
+
181
+ When executed as follows
182
+
183
+ ```
184
+ $ ./examples/multiple_modules.rb trace debug2
185
+ ```
186
+
187
+ it gives the following output:
188
+
189
+ ```
190
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.201933, some_level]:
191
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202013, Notice]: starting up
192
+ Suppressed severities: [:trace, :debug2]
193
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202050, Informational]: Calling helpers
194
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202073, Debug-0]:
195
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202091, Debug-1]:
196
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202110, Debug-0]:
197
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202125, Notice]:
198
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202167, Critical]:
199
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202199, Alert]:
200
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202243, Informational]: Creating instance of OrgClass
201
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202269, Debug-0]:
202
+ [multiple_modules, 70350289450660, 2020-06-03 20:25:49.202286, Notice]:
203
+ ```
204
+
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *([ '..' ] * 1), 'lib')
4
+
5
+ # ######################################
6
+ # requires
7
+
8
+ require 'pantheios'
9
+
10
+ # ######################################
11
+ # modules
12
+
13
+ module Organisation
14
+
15
+ module Helpers
16
+
17
+ include ::Pantheios
18
+
19
+ def with_trace
20
+
21
+ trace
22
+ end
23
+
24
+ def with_debug0; log(:debug0); end
25
+ def with_debug1; log(:debug1); end
26
+ def with_informational; log(:informational); end
27
+ def with_notice; log(:notice); end
28
+ def with_warning; log(:warning); end
29
+ def with_failure; log(:failure); end
30
+ def with_critical; log(:critical); end
31
+ def with_alert; log(:alert); end
32
+
33
+ def helper1
34
+
35
+ trace
36
+
37
+ with_debug0
38
+
39
+ with_notice
40
+ end
41
+
42
+ end # module Helpers
43
+
44
+ class OrgClass
45
+
46
+ include Helpers
47
+ include ::Pantheios
48
+
49
+ def initialize()
50
+
51
+ trace
52
+
53
+ log(:debug2) { 'initialised instance of OrgClass' }
54
+
55
+ helper1
56
+ end
57
+
58
+ end # class OrgClas
59
+
60
+ end # module Organisation
61
+
62
+ # ######################################
63
+ # includes
64
+
65
+ include ::Organisation::Helpers
66
+
67
+ include ::Pantheios
68
+
69
+ # ######################################
70
+ # constants
71
+
72
+ SUPPRESSED_SEVERITIES = %i{
73
+
74
+
75
+ }
76
+
77
+ # ######################################
78
+ # diagnostics
79
+
80
+ def detect_suppression argv
81
+
82
+ argv.each do |arg|
83
+
84
+ SUPPRESSED_SEVERITIES << arg.to_sym
85
+ end
86
+ end
87
+
88
+ class FrontEnd
89
+
90
+ def severity_logged? severity
91
+
92
+ case severity
93
+ when ::Symbol
94
+
95
+ !SUPPRESSED_SEVERITIES.include?(severity)
96
+ else
97
+
98
+ true
99
+ end
100
+ end
101
+ end
102
+
103
+ Pantheios::Core.set_front_end FrontEnd.new
104
+
105
+ # ######################################
106
+ # main
107
+
108
+ detect_suppression ARGV
109
+
110
+ log(:some_level)
111
+
112
+ log(:notice, 'starting up')
113
+
114
+ puts "Suppressed severities: #{SUPPRESSED_SEVERITIES}"
115
+
116
+ log(:info) { "Calling helpers" }
117
+
118
+ with_trace
119
+
120
+ with_debug0
121
+ with_debug1
122
+ helper1
123
+ with_critical
124
+ with_alert
125
+
126
+ log(:info) { "Creating instance of OrgClass" }
127
+
128
+ oc = Organisation::OrgClass.new
129
+
130
+ # ############################## end of file ############################# #
131
+
132
+
@@ -7,12 +7,13 @@
7
7
  # namespace module
8
8
  #
9
9
  # Created: 2nd April 2011
10
- # Updated: 12th March 2018
10
+ # Updated: 3rd June 2020
11
11
  #
12
12
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
13
13
  #
14
14
  # Author: Matthew Wilson
15
15
  #
16
+ # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
16
17
  # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
17
18
  # All rights reserved.
18
19
  #
@@ -59,20 +60,21 @@ module StockSeverityLevels
59
60
 
60
61
  STOCK_SEVERITY_LEVELS_ = {
61
62
 
62
- :violation => [ 1, 'Violation', [ :emergency ] ],
63
- :alert => [ 2, 'Alert' ],
64
- :critical => [ 3, 'Critical' ],
65
- :failure => [ 4, 'Failure' ],
66
- :warning => [ 5, 'Warning', [ :warn ] ],
67
- :notice => [ 6, 'Notice' ],
68
- :informational => [ 7, 'Informational', [ :info ] ],
69
- :debug0 => [ 8, 'Debug-0' ],
70
- :debug1 => [ 9, 'Debug-1' ],
71
- :debug2 => [ 10, 'Debug-2' ],
72
- :debug3 => [ 11, 'Debug-3' ],
73
- :debug4 => [ 12, 'Debug-4' ],
74
- :trace => [ 15, 'Trace' ],
75
- :benchmark => [ 16, 'Benchmark' ],
63
+ :violation => [ 1, 'Violation', :relative, [ :emergency ] ],
64
+ :alert => [ 2, 'Alert', :relative ],
65
+ :critical => [ 3, 'Critical', :relative ],
66
+ :failure => [ 4, 'Failure', :relative, [ :fail ] ],
67
+ :warning => [ 5, 'Warning', :relative, [ :warn ] ],
68
+ :notice => [ 6, 'Notice', :relative ],
69
+ :informational => [ 7, 'Informational', :relative, [ :info ] ],
70
+ :debug0 => [ 8, 'Debug-0', :relative ],
71
+ :debug1 => [ 9, 'Debug-1', :relative ],
72
+ :debug2 => [ 10, 'Debug-2', :relative ],
73
+ :debug3 => [ 11, 'Debug-3', :relative ],
74
+ :debug4 => [ 12, 'Debug-4', :relative ],
75
+ :debug5 => [ 13, 'Debug-5', :relative ],
76
+ :trace => [ 15, 'Trace', :relative ],
77
+ :benchmark => [ 16, 'Benchmark', :separate ],
76
78
  }
77
79
 
78
80
  def self.create_level_keys m
@@ -81,7 +83,7 @@ module StockSeverityLevels
81
83
 
82
84
  m.each do |k, ar|
83
85
 
84
- (ar[2] || []).each do |al|
86
+ (ar[3] || []).each do |al|
85
87
 
86
88
  r << al
87
89
  end
@@ -99,7 +101,7 @@ module StockSeverityLevels
99
101
  warn 'invalid start-up' unless ::Symbol === s
100
102
  warn 'invalid start-up' unless ::Array === ar
101
103
 
102
- ([s] + (ar[2] || [])).each do |al|
104
+ ([s] + (ar[3] || [])).each do |al|
103
105
 
104
106
  r[al] = ar[0]
105
107
  end
@@ -107,6 +109,7 @@ module StockSeverityLevels
107
109
 
108
110
  r
109
111
  end
112
+
110
113
  def self.create_level_string_map m
111
114
 
112
115
  r = {}
@@ -116,7 +119,7 @@ module StockSeverityLevels
116
119
  warn 'invalid start-up' unless ::Symbol === s
117
120
  warn 'invalid start-up' unless ::Array === ar
118
121
 
119
- ([s] + (ar[2] || [])).each do |al|
122
+ ([s] + (ar[3] || [])).each do |al|
120
123
 
121
124
  r[al] = ar[1]
122
125
  end
@@ -124,20 +127,74 @@ module StockSeverityLevels
124
127
 
125
128
  r
126
129
  end
130
+
131
+ def self.create_level_aliases m
132
+
133
+ r = {}
134
+
135
+ m.each do |s, ar|
136
+
137
+ warn 'invalid start-up' unless ::Symbol === s
138
+ warn 'invalid start-up' unless ::Array === ar
139
+
140
+ ([s] + (ar[3] || [])).each do |al|
141
+
142
+ r[al] = s
143
+ end
144
+ end
145
+
146
+ r
147
+ end
148
+
149
+ def self.create_level_relative_map m
150
+
151
+ r = {}
152
+
153
+ m.each do |s, ar|
154
+
155
+ warn 'invalid start-up' unless ::Symbol === s
156
+ warn 'invalid start-up' unless ::Array === ar
157
+
158
+ relativity = ar[2]
159
+
160
+ case relativity
161
+ when :relative
162
+
163
+ ([s] + (ar[3] || [])).each do |al|
164
+
165
+ r[al] = relativity
166
+ end
167
+ else
168
+
169
+ ;
170
+ end
171
+ end
172
+
173
+ r
174
+ end
127
175
  end
128
176
  public
129
177
 
130
- # Ordered list of stock severity levels, without any aliases
178
+ # Ordered list of stock severity level symbols, without any aliases
131
179
  STOCK_SEVERITY_LEVELS_PRIME = Internal_::STOCK_SEVERITY_LEVELS_.keys
132
180
 
133
- # Ordered list of stock severity levels, some of which may be aliases
181
+ # Unordered list of stock severity levels, some of which may be aliases
134
182
  STOCK_SEVERITY_LEVELS = Internal_.create_level_keys Internal_::STOCK_SEVERITY_LEVELS_
135
183
 
136
- # Mapping of severity levels (and level aliases) to integral
184
+ # Mapping of severity level aliases - with may be symbols and strings -
185
+ # to the prime stock severity level symbols
186
+ STOCK_SEVERITY_LEVEL_ALIASES = Internal_.create_level_aliases Internal_::STOCK_SEVERITY_LEVELS_
187
+
188
+ # Mapping of severity level aliases - with may be symbols and strings -
189
+ # containing only those levels that are relative, i.e. may participate
190
+ # meaningfully in a threshold-based filtering
191
+ STOCK_SEVERITY_LEVELS_RELATIVE = Internal_.create_level_relative_map Internal_::STOCK_SEVERITY_LEVELS_
192
+
193
+ # Mapping of severity level (and level alias) symbols to integral
137
194
  # equivalent
138
195
  STOCK_SEVERITY_LEVEL_VALUES = Internal_.create_level_value_map Internal_::STOCK_SEVERITY_LEVELS_
139
196
 
140
- # Mapping of severity levels (and level aliases) to string
197
+ # Mapping of severity level (and level alias) symbols to string
141
198
  STOCK_SEVERITY_LEVEL_STRINGS = Internal_.create_level_string_map Internal_::STOCK_SEVERITY_LEVELS_
142
199
 
143
200
  end # module StockSeverityLevels
@@ -0,0 +1,135 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/pantheios/front_ends/threshold_front_end.rb
4
+ #
5
+ # Purpose: Definition of the ::Pantheios::FrontEnds::ThresholdFrontEnd
6
+ # class
7
+ #
8
+ # Created: 3rd June 2020
9
+ # Updated: 3rd June 2020
10
+ #
11
+ # Home: http://github.com/synesissoftware/Pantheios-Ruby
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2020, Matthew Wilson and Synesis Information Systems
16
+ # All rights reserved.
17
+ #
18
+ # Redistribution and use in source and binary forms, with or without
19
+ # modification, are permitted provided that the following conditions are
20
+ # met:
21
+ #
22
+ # * Redistributions of source code must retain the above copyright
23
+ # notice, this list of conditions and the following disclaimer.
24
+ #
25
+ # * Redistributions in binary form must reproduce the above copyright
26
+ # notice, this list of conditions and the following disclaimer in the
27
+ # documentation and/or other materials provided with the distribution.
28
+ #
29
+ # * Neither the names of the copyright holder nor the names of its
30
+ # contributors may be used to endorse or promote products derived from
31
+ # this software without specific prior written permission.
32
+ #
33
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
37
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
+ #
45
+ # ######################################################################## #
46
+
47
+
48
+ =begin
49
+ =end
50
+
51
+ require 'pantheios/application_layer/stock_severity_levels'
52
+
53
+ module Pantheios
54
+ module FrontEnds
55
+
56
+ # A class that fulfils the Pantheios *FrontEnd* protocol that implements
57
+ # +severity_logged?+ based on a threshold specified to the initialiser
58
+ #
59
+ # NOTE: The *FrontEnd* protocol is implemented by a class that provides
60
+ # the instance method +severity_logged?(severity : Object)+
61
+ class ThresholdFrontEnd
62
+
63
+ include ::Pantheios::ApplicationLayer
64
+
65
+ # Initialises the instance
66
+ #
67
+ # === Signature
68
+ #
69
+ # * *Parameters:*
70
+ # - +threshold_severity+ [ ::Symbol ] The threshold severity
71
+ #
72
+ # * *Options:*
73
+ # - +value_lookup_map+ [ ::Hash ] A map that is used to lookup
74
+ # +severity+ values (that are not +::Integer+) in
75
+ # +severity_logged?+. May be +nil+, in which case
76
+ # +::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES+
77
+ # is used
78
+ def initialize(threshold_severity, **options)
79
+
80
+ m = options[:value_lookup_map]
81
+
82
+ raise TypeError, "value given for :value_lookup_map must be a #{::Hash}" if m && !m.respond_to?(:to_hash)
83
+
84
+ if m
85
+
86
+ @value_lookup_map = m
87
+ @relativity_lookup_map = ::Hash.new(:relative)
88
+ else
89
+
90
+ @value_lookup_map = StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
91
+ @relativity_lookup_map = StockSeverityLevels::STOCK_SEVERITY_LEVELS_RELATIVE
92
+ end
93
+
94
+ self.threshold = threshold_severity
95
+ end
96
+
97
+ def severity_logged? severity
98
+
99
+ case severity
100
+ when ::Integer
101
+
102
+ v = severity
103
+ else
104
+
105
+ v = @value_lookup_map[severity] or warn "unknown severity level '#{severity}' (#{severity.class})"
106
+ end
107
+
108
+ return true if v.nil?
109
+
110
+ v <= @threshold_v
111
+ end
112
+
113
+ # assigns the threshold
114
+ #
115
+ # * *Parameters:*
116
+ # - +threshold_severity+ [ ::Symbol ] The threshold severity
117
+ def threshold=(threshold_severity)
118
+
119
+ raise TypeError, "threshold_severity must be a #{::Symbol}" unless ::Symbol === threshold_severity
120
+
121
+ @threshold_v = @value_lookup_map[threshold_severity] if @relativity_lookup_map[threshold_severity] or raise ArgumentError, "unknown threshold severity level '#{threshold_severity}' (#{threshold_severity.class})"
122
+ @threshold = threshold_severity
123
+
124
+ nil
125
+ end
126
+ attr_reader :threshold
127
+
128
+ end # class ThresholdFrontEnd
129
+
130
+ end # module FrontEnds
131
+ end # module Pantheios
132
+
133
+ # ############################## end of file ############################# #
134
+
135
+
@@ -5,12 +5,13 @@
5
5
  # Purpose: The Pantheios.Ruby "globals" (::Pantheios::Globals)
6
6
  #
7
7
  # Created: 24th December 2017
8
- # Updated: 4th February 2018
8
+ # Updated: 3rd June 2020
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2017-2018, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -57,6 +58,18 @@ module Pantheios
57
58
  #
58
59
  # === Variables
59
60
  #
61
+ # * *HAS_CASCADED_INCLUDES* [boolean] Determines whether including
62
+ # +::Pantheios+ also includes all relevant parts of subordinate
63
+ # namespaces. See the documentation for the +::Pantheios+ namespace for
64
+ # further details
65
+ #
66
+ # * *INITIAL_SERVICE_CLASSES* [ svc-class, [ svc-class ] ] Specifies
67
+ # the service class(es) that will be used to create the initial service
68
+ # instance. Ignored if INITIAL_SERVICE_INSTANCES specifies an instance
69
+ #
70
+ # * *INITIAL_SERVICE_INSTANCES* [ svc-instance, [ svc-instance ] ] Specifies
71
+ # the initial service instance
72
+ #
60
73
  # * *MAIN_THREAD_NAME* A string specifying the main thread name, or an array
61
74
  # containing a thread instance and a string specifying the thread and its
62
75
  # name
@@ -65,11 +78,6 @@ module Pantheios
65
78
  # form is used then the first initialising thread of Pantheios.Ruby will
66
79
  # be the named thread
67
80
  #
68
- # * *HAS_CASCADED_INCLUDES* [boolean] Determines whether including
69
- # +::Pantheios+ also includes all relevant parts of subordinate
70
- # namespaces. See the documentation for the +::Pantheios+ namespace for
71
- # further details
72
- #
73
81
  # * *PROCESS_NAME* A string specifying the process name, or one of the
74
82
  # recognised symbols - :script, :script_basename, :script_dirname,
75
83
  # :script_realpath, :script_stem - that directs inference of the process
@@ -9,6 +9,8 @@ module ReflectionUtil
9
9
  ROOT_CLASSES = [ ::Object, ::BasicObject ]
10
10
  end
11
11
 
12
+ # Obtains a list of all classes pertaining to +o+, excepting root
13
+ # objects (+::Object+ and +::BaseObject+).
12
14
  def self.non_root_classes o
13
15
 
14
16
  return [] if o.nil?
@@ -22,6 +22,7 @@ module ThreadUtil
22
22
  t.thread_name = name
23
23
  end
24
24
 
25
+ # Obtains the name of the calling thread
25
26
  def self.get_thread_name t
26
27
 
27
28
  t ||= Thread.current
@@ -5,12 +5,13 @@
5
5
  # Purpose: Version for Pantheios.Ruby library
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 5th June 2019
8
+ # Updated: 3rd June 2020
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2011-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -50,7 +51,7 @@
50
51
  module Pantheios
51
52
 
52
53
  # Current version of the Pantheios.Ruby library
53
- VERSION = '0.20.3.1'
54
+ VERSION = '0.21.0'
54
55
 
55
56
  private
56
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -26,12 +26,15 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
26
26
  debug2
27
27
  debug3
28
28
  debug4
29
+ debug5
29
30
  trace
31
+ benchmark
30
32
  }.map { |s| s.to_sym }
31
33
 
32
34
  EXPECTED_LEVELS = %w{
33
35
 
34
36
  emergency
37
+ fail
35
38
  info
36
39
  warn
37
40
  }.map { |s| s.to_sym } + EXPECTED_LEVELS_PRIME
@@ -51,6 +54,7 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
51
54
  if defined? StockSeverityLevels
52
55
 
53
56
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVELS)
57
+ assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVELS_PRIME)
54
58
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_VALUES)
55
59
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_STRINGS)
56
60
  end
@@ -58,18 +62,36 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
58
62
 
59
63
  def test_StockSeverityLevels_expected_levels
60
64
 
65
+ # all the ones that we expect exist
66
+
61
67
  EXPECTED_LEVELS.each do |sev|
62
68
 
63
69
  assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
64
70
  end
71
+
72
+ # we expect all the ones that exist
73
+
74
+ StockSeverityLevels::STOCK_SEVERITY_LEVELS.each do |sev|
75
+
76
+ assert(EXPECTED_LEVELS.include?(sev), "found unexpected level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
77
+ end
65
78
  end
66
79
 
67
80
  def test_StockSeverityLevels_expected_prime_levels
68
81
 
82
+ # all the ones that we expect exist
83
+
69
84
  EXPECTED_LEVELS_PRIME.each do |sev|
70
85
 
71
86
  assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
72
87
  end
88
+
89
+ # we expect all the ones that exist
90
+
91
+ StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME.each do |sev|
92
+
93
+ assert(EXPECTED_LEVELS_PRIME.include?(sev), "found unexpected level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
94
+ end
73
95
  end
74
96
 
75
97
  def test_StockSeverityLevels_expected_prime_levels_have_distinct_values
@@ -99,5 +121,50 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
99
121
  strings[string] = string
100
122
  end
101
123
  end
124
+
125
+ def test_StockSeverityLevels_aliases
126
+
127
+ aliases = StockSeverityLevels::STOCK_SEVERITY_LEVEL_ALIASES
128
+
129
+ assert_equal :violation, aliases[:violation]
130
+ assert_equal :violation, aliases[:emergency]
131
+
132
+ assert_equal :alert, aliases[:alert]
133
+
134
+ assert_equal :critical, aliases[:critical]
135
+
136
+ assert_equal :failure, aliases[:failure]
137
+ assert_equal :failure, aliases[:fail]
138
+ #assert_equal :failure, aliases[:error]
139
+
140
+ assert_equal :warning, aliases[:warning]
141
+ assert_equal :warning, aliases[:warn]
142
+
143
+ assert_equal :notice, aliases[:notice]
144
+
145
+ assert_equal :informational, aliases[:informational]
146
+ assert_equal :informational, aliases[:info]
147
+
148
+ %i{ debug0 debug1 debug2 debug3 debug4 debug5 }.each do |sev|
149
+
150
+ assert_equal sev, aliases[sev]
151
+ end
152
+
153
+ assert_equal :trace, aliases[:trace]
154
+
155
+ assert_equal :benchmark, aliases[:benchmark]
156
+ end
157
+
158
+ def test_StockSeverityLevels_recognised_values_are_nil
159
+
160
+ EXPECTED_LEVELS.each do |sev|
161
+
162
+ assert_not_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev]
163
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev.to_s]
164
+ end
165
+
166
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[nil]
167
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES['failure']
168
+ end
102
169
  end
103
170
 
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/front_ends/threshold_front_end'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_FrontEnds_ThresholdFrontEnd < Test::Unit::TestCase
10
+
11
+ include ::Pantheios::FrontEnds
12
+
13
+ def test_SimpleConsoleLogService_type_exists
14
+
15
+ assert defined? ThresholdFrontEnd
16
+ end
17
+
18
+ def test_construct_with_invalid_parameters
19
+
20
+ assert_raise(::TypeError) { ThresholdFrontEnd.new('notice') }
21
+
22
+ assert_raise_with_message(::ArgumentError, /unknown threshold severity level.*something_else.*Symbol/) { ThresholdFrontEnd.new(:something_else) }
23
+
24
+ ThresholdFrontEnd.new(:notice)
25
+ ThresholdFrontEnd.new(:notice, value_lookup_map: Hash.new)
26
+ assert_raise_with_message(::TypeError, /:value_lookup_map must be.*Hash/) { ThresholdFrontEnd.new(:notice, value_lookup_map: Array.new) }
27
+ end
28
+
29
+ def test_default_construct
30
+
31
+ fe = ThresholdFrontEnd.new(:notice)
32
+
33
+ assert_equal :notice, fe.threshold
34
+
35
+ assert_true fe.severity_logged?(:violation)
36
+ assert_true fe.severity_logged?(:alert)
37
+ assert_true fe.severity_logged?(:critical)
38
+ assert_true fe.severity_logged?(:failure)
39
+ assert_true fe.severity_logged?(:warning)
40
+ assert_true fe.severity_logged?(:notice)
41
+ assert_false fe.severity_logged?(:informational)
42
+ assert_false fe.severity_logged?(:debug0)
43
+ assert_false fe.severity_logged?(:debug1)
44
+ assert_false fe.severity_logged?(:debug2)
45
+ assert_false fe.severity_logged?(:debug3)
46
+ assert_false fe.severity_logged?(:debug4)
47
+ assert_false fe.severity_logged?(:debug5)
48
+ assert_false fe.severity_logged?(:trace)
49
+ end
50
+
51
+ def test_default_construct_and_change_threshold
52
+
53
+ fe = ThresholdFrontEnd.new(:notice)
54
+
55
+ assert_equal :notice, fe.threshold
56
+
57
+ fe.threshold = :failure
58
+
59
+ assert_equal :failure, fe.threshold
60
+
61
+ assert_true fe.severity_logged?(:violation)
62
+ assert_true fe.severity_logged?(:alert)
63
+ assert_true fe.severity_logged?(:critical)
64
+ assert_true fe.severity_logged?(:failure)
65
+ assert_false fe.severity_logged?(:warning)
66
+ assert_false fe.severity_logged?(:notice)
67
+ assert_false fe.severity_logged?(:informational)
68
+ assert_false fe.severity_logged?(:debug0)
69
+ assert_false fe.severity_logged?(:debug1)
70
+ assert_false fe.severity_logged?(:debug2)
71
+ assert_false fe.severity_logged?(:debug3)
72
+ assert_false fe.severity_logged?(:debug4)
73
+ assert_false fe.severity_logged?(:debug5)
74
+ assert_false fe.severity_logged?(:trace)
75
+ end
76
+
77
+ def test_use_custom_thresholds
78
+
79
+ value_lookup_map = {
80
+
81
+ FATAL: 1,
82
+ ERROR: 2,
83
+ WARN: 3,
84
+ INFO: 4,
85
+ DEBUG: 5,
86
+ }
87
+
88
+ fe = ThresholdFrontEnd.new(:INFO, value_lookup_map: value_lookup_map)
89
+
90
+ assert_equal :INFO, fe.threshold
91
+
92
+ assert_true fe.severity_logged?(:FATAL)
93
+ assert_true fe.severity_logged?(:ERROR)
94
+ assert_true fe.severity_logged?(:WARN)
95
+ assert_true fe.severity_logged?(:INFO)
96
+ assert_false fe.severity_logged?(:DEBUG)
97
+ end
98
+ end
99
+
100
+ # ############################## end of file ############################# #
101
+
102
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
@@ -89,7 +89,7 @@ class Test_MultiplexingLogservice < Test::Unit::TestCase
89
89
 
90
90
  log_multiple_statements svc
91
91
 
92
- assert_equal 11, svc_0.items.size
92
+ assert_equal 12, svc_0.items.size
93
93
  assert_equal 4, svc_1.items.size
94
94
  assert_equal 6, svc_2.items.size
95
95
  end
@@ -104,7 +104,7 @@ class Test_MultiplexingLogservice < Test::Unit::TestCase
104
104
 
105
105
  log_multiple_statements svc
106
106
 
107
- assert_equal 11, svc_0.items.size
107
+ assert_equal 12, svc_0.items.size
108
108
  assert_equal 4, svc_1.items.size
109
109
  assert_equal 6, svc_2.items.size
110
110
  end
@@ -119,7 +119,7 @@ class Test_MultiplexingLogservice < Test::Unit::TestCase
119
119
 
120
120
  log_multiple_statements svc
121
121
 
122
- assert_equal 11, svc_0.items.size
122
+ assert_equal 12, svc_0.items.size
123
123
  assert_equal 4, svc_1.items.size
124
124
  assert_equal 6, svc_2.items.size
125
125
  end
@@ -134,7 +134,7 @@ class Test_MultiplexingLogservice < Test::Unit::TestCase
134
134
 
135
135
  log_multiple_statements svc
136
136
 
137
- assert_equal 11, svc_0.items.size
137
+ assert_equal 12, svc_0.items.size
138
138
  assert_equal 4, svc_1.items.size
139
139
  assert_equal 6, svc_2.items.size
140
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pantheios-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.3.1
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xqsr3
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.31'
19
+ version: '0.36'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.31'
26
+ version: '0.36'
27
27
  description: 'A Ruby version of the popular C++ (and .NET) logging API library
28
28
 
29
29
  '
@@ -34,6 +34,8 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - LICENSE
36
36
  - README.md
37
+ - examples/multiple_modules.md
38
+ - examples/multiple_modules.rb
37
39
  - examples/simple_logging.md
38
40
  - examples/simple_logging.rb
39
41
  - lib/pantheios.rb
@@ -42,6 +44,7 @@ files:
42
44
  - lib/pantheios/application_layer/param_name_list.rb
43
45
  - lib/pantheios/application_layer/stock_severity_levels.rb
44
46
  - lib/pantheios/core.rb
47
+ - lib/pantheios/front_ends/threshold_front_end.rb
45
48
  - lib/pantheios/globals.rb
46
49
  - lib/pantheios/services.rb
47
50
  - lib/pantheios/services/multiplexing_log_service.rb
@@ -67,6 +70,8 @@ files:
67
70
  - test/unit/application_layer/ts_all.rb
68
71
  - test/unit/core/tc_core_1.rb
69
72
  - test/unit/core/ts_all.rb
73
+ - test/unit/front_ends/tc_threshold_front_end.rb
74
+ - test/unit/front_ends/ts_all.rb
70
75
  - test/unit/services/tc_multiplexing_log_service.rb
71
76
  - test/unit/services/tc_null_log_service.rb
72
77
  - test/unit/services/tc_simple_console_log_service.rb