pantheios-ruby 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35032757734802235a87eb0d7ce2e6d4830a906f
4
+ data.tar.gz: 14f80938e0d943a1921449cb29025757f6e839a1
5
+ SHA512:
6
+ metadata.gz: fbb767e3cea06e7612c37be433e675af34be2cad80880cb79d87857f3e88acab4f6f2db7c0e0cc88e800d7b499ffb17000bea2a5388c08a1db7da93a31ca88a7
7
+ data.tar.gz: 6019963f5c8a9e299e181f854a1190fe504d782b8b16f3d96d7ae4acf4a97617d4615b4b1939ea2362d575c6b6f2bc45eb45a491de5af00b9a9c6610bc4fd44b
@@ -0,0 +1,39 @@
1
+
2
+ # The main module for Pantheios
3
+ #
4
+ # Pantheios is both a namespace module and an inclusion module. When
5
+ # included, it results in the automatic inclusion of the inclusion modules
6
+ # +Pantheios::API+, +Pantheios::ApplicationLayer+, and +Pantheios::Util+ (as
7
+ # well as certain sub modules of +Pantheios::Util+; see +Pantheios::Util+
8
+ # for details), unless the global symbol
9
+ # +::Pantheios::Globals.HAS_CASCADED_INCLUDES+ is truey
10
+ module Pantheios
11
+ end # module Pantheios
12
+
13
+ require 'pantheios/globals'
14
+
15
+ require 'pantheios/api'
16
+ require 'pantheios/application_layer'
17
+ require 'pantheios/util'
18
+ require 'pantheios/version'
19
+
20
+ module Pantheios
21
+
22
+ def self.included receiver
23
+
24
+ if ::Pantheios::Globals.HAS_CASCADED_INCLUDES
25
+
26
+ receiver.class_eval do
27
+
28
+ include ::Pantheios::API
29
+ include ::Pantheios::ApplicationLayer
30
+ include ::Pantheios::Util
31
+ end
32
+ end
33
+
34
+ ::Pantheios::Core.register_include self, receiver
35
+ end
36
+
37
+ end # module Pantheios
38
+
39
+
@@ -0,0 +1,275 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/pantheios/api.rb
4
+ #
5
+ # Purpose: The Pantheios.Ruby API (::Pantheios::API)
6
+ #
7
+ # Created: 2nd April 2011
8
+ # Updated: 24th December 2017
9
+ #
10
+ # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2011-2017, Matthew Wilson and Synesis Software
15
+ # All rights reserved.
16
+ #
17
+ # Redistribution and use in source and binary forms, with or without
18
+ # modification, are permitted provided that the following conditions are
19
+ # met:
20
+ #
21
+ # * Redistributions of source code must retain the above copyright
22
+ # notice, this list of conditions and the following disclaimer.
23
+ #
24
+ # * Redistributions in binary form must reproduce the above copyright
25
+ # notice, this list of conditions and the following disclaimer in the
26
+ # documentation and/or other materials provided with the distribution.
27
+ #
28
+ # * Neither the names of the copyright holder nor the names of its
29
+ # contributors may be used to endorse or promote products derived from
30
+ # this software without specific prior written permission.
31
+ #
32
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+ #
44
+ # ######################################################################## #
45
+
46
+
47
+ =begin
48
+ =end
49
+
50
+
51
+ require 'pantheios/application_layer/param_name_list'
52
+ require 'pantheios/application_layer/stock_severity_levels'
53
+ require 'pantheios/util/version_util'
54
+
55
+ require 'pantheios/core'
56
+
57
+
58
+ module Pantheios
59
+ # This inclusion module specifies the main logging API methods, including:
60
+ #
61
+ # - log
62
+ # - log_v
63
+ # - trace
64
+ # - trace_v
65
+ #
66
+ # as well as those that may be overridden:
67
+ #
68
+ # - severity_logged?
69
+ # - tracing?
70
+ #
71
+ # - prefix_elements
72
+ # - process_id
73
+ # - program_name
74
+ # - severity_string severity
75
+ # - thread_id
76
+ # - timestamp t
77
+ module API
78
+
79
+ # Logs an arbitrary set of parameters at the given severity level
80
+ def log severity, *args
81
+
82
+ return nil unless severity_logged? severity
83
+
84
+ log_or_trace 1, severity, args
85
+ end
86
+
87
+ # Logs an array of parameters at the given severity level
88
+ def log_v severity, argv
89
+
90
+ return nil unless severity_logged? severity
91
+
92
+ log_or_trace 1, severity, argv
93
+ end
94
+
95
+ # Logs an arbitrary set of parameters at the Trace (:trace) level
96
+ def trace *args
97
+
98
+ return nil unless tracing?
99
+
100
+ ::Pantheios::Core.trace_v_prep self, 1, args
101
+ end
102
+
103
+ # Logs an array of parameters at the Trace (:trace) level
104
+ def trace_v argv
105
+
106
+ return nil unless tracing?
107
+
108
+ ::Pantheios::Core.trace_v_prep self, 1, argv
109
+ end
110
+
111
+ if Util::VersionUtil.version_compare(RUBY_VERSION, [ 2, 1 ]) >= 0
112
+
113
+ def trace_blv b, lvars
114
+
115
+ return nil unless tracing?
116
+
117
+ ::Pantheios::Core.trace_v_impl self, 1, ApplicationLayer::ParamNameList[*lvars], :trace, lvars.map { |lv| b.local_variable_get(lv) }
118
+ end
119
+ end # RUBY_VERSION
120
+
121
+ if Util::VersionUtil.version_compare(RUBY_VERSION, [ 2, 2 ]) >= 0
122
+
123
+ def trace_b b
124
+
125
+ return nil unless tracing?
126
+
127
+ ::Pantheios::Core.trace_v_impl self, 1, ApplicationLayer::ParamNameList[*b.local_variables], :trace, b.local_variables.map { |lv| b.local_variable_get(lv) }
128
+ end
129
+ end # RUBY_VERSION
130
+
131
+
132
+ # Determines whether a given severity is logged
133
+ #
134
+ # === Signature
135
+ #
136
+ # * *Parameters:*
137
+ # - +severity+:: The severity level, which should be a known log
138
+ # severity symbol or an integral equivalent
139
+ #
140
+ # * *Returns:*
141
+ # a +truey+ value if the severity should be logged; a +falsey+ value
142
+ # otherwise
143
+ def severity_logged? severity
144
+
145
+ ::Pantheios::Core.severity_logged? severity
146
+ end
147
+
148
+ # Determines whether tracing (severity == :trace) is enabled. This is
149
+ # used in the trace methods (+trace+, +trace_v+, +trace_blv+, +trace_b+)
150
+ # and therefore it may be overridden independently of +severity_logged?+
151
+ def tracing?
152
+
153
+ severity_logged? :trace
154
+ end
155
+
156
+
157
+
158
+ # Defines the ordered list of log-statement elements
159
+ #
160
+ # === Elements
161
+ #
162
+ # Elements can be one of:
163
+ # - +:program_name+
164
+ # - +:process_id+
165
+ # - +:severity+
166
+ # - +:thread_id+
167
+ # - +:timestamp+
168
+ #
169
+ # This is called from +prefix+
170
+ def prefix_elements
171
+
172
+ [ :program_name, :thread_id, :timestamp, :severity ]
173
+ end
174
+
175
+ # Obtains the process id
176
+ #
177
+ # Unless overridden, returns the value provided by
178
+ # +::Pantheios::Core::process_id+
179
+ def process_id
180
+
181
+ ::Pantheios::Core.process_id
182
+ end
183
+
184
+ # Obtains the program name
185
+ #
186
+ # Unless overridden, returns the value provided by
187
+ # +::Pantheios::Core::program_name+
188
+ def program_name
189
+
190
+ ::Pantheios::Core.program_name
191
+ end
192
+
193
+ # Obtains the string corresponding to the severity
194
+ #
195
+ # Unless overridden, returns the value provided by
196
+ # +::Pantheios::Core::severity_string+
197
+ def severity_string severity
198
+
199
+ ::Pantheios::Core.severity_string severity
200
+ end
201
+
202
+ # Obtains the thread id
203
+ #
204
+ # Unless overridden, returns the value provided by
205
+ # +::Pantheios::Core::thread_id+
206
+ def thread_id
207
+
208
+ ::Pantheios::Core.thread_id
209
+ end
210
+
211
+ # Obtains a string-form of the timestamp
212
+ #
213
+ # Unless overridden, returns the value provided by
214
+ # +::Pantheios::Core::timestamp+
215
+ def timestamp t
216
+
217
+ ::Pantheios::Core.timestamp t, nil
218
+ end
219
+
220
+ def prefix t, severity
221
+
222
+ prefix_elements.map do |el|
223
+
224
+ case el
225
+ when :program_name
226
+
227
+ program_name
228
+ when :process_id
229
+
230
+ process_id
231
+ when :severity
232
+
233
+ severity_string severity
234
+ when :thread_id
235
+
236
+ thread_id
237
+ when :timestamp
238
+
239
+ timestamp t
240
+ else
241
+
242
+ s = ::Symbol === el ? ":#{el}" : el.to_s
243
+
244
+ warn "ignoring unrecognised prefix_element '#{s}'"
245
+
246
+ nil
247
+ end
248
+ end.join(', ') # TODO: need to do more intelligent joining
249
+ end
250
+
251
+
252
+ def self.included receiver
253
+
254
+ receiver.extend self
255
+
256
+ ::Pantheios::Core.register_include self, receiver
257
+ end
258
+
259
+ private
260
+
261
+ # Private implementation method that should not need to be overridden
262
+ def log_or_trace call_depth, severity, argv
263
+
264
+ if :trace == severity
265
+
266
+ return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, severity, argv
267
+ end
268
+
269
+ ::Pantheios::Core.log_raw self, severity, argv.join
270
+ end
271
+
272
+ end # module API
273
+ end # module Pantheios
274
+
275
+
@@ -0,0 +1,20 @@
1
+
2
+ require 'pantheios/application_layer/param_name_list'
3
+ require 'pantheios/application_layer/stock_severity_levels'
4
+
5
+ require 'pantheios/core'
6
+
7
+ module Pantheios
8
+ module ApplicationLayer
9
+
10
+ def self.included receiver
11
+
12
+ receiver.extend self
13
+
14
+ ::Pantheios::Core.register_include self, receiver
15
+ end
16
+
17
+ end # module ApplicationLayer
18
+ end # module Pantheios
19
+
20
+
@@ -0,0 +1,13 @@
1
+
2
+ module Pantheios
3
+ module ApplicationLayer
4
+
5
+ class ParamNameList < Array
6
+ end
7
+
8
+ ParamNames = ParamNameList
9
+
10
+ end # module ApplicationLayer
11
+ end # module Pantheios
12
+
13
+
@@ -0,0 +1,146 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/pantheios/application_layer/stock_severity_levels.rb
4
+ #
5
+ # Purpose: Definition of the
6
+ # Pantheios::ApplicationLayer::StockSeverityLevels include /
7
+ # namespace module
8
+ #
9
+ # Created: 2nd April 2011
10
+ # Updated: 6th January 2018
11
+ #
12
+ # Home: http://github.com/synesissoftware/Pantheios-Ruby
13
+ #
14
+ # Author: Matthew Wilson
15
+ #
16
+ # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
17
+ # All rights reserved.
18
+ #
19
+ # Redistribution and use in source and binary forms, with or without
20
+ # modification, are permitted provided that the following conditions are
21
+ # met:
22
+ #
23
+ # * Redistributions of source code must retain the above copyright
24
+ # notice, this list of conditions and the following disclaimer.
25
+ #
26
+ # * Redistributions in binary form must reproduce the above copyright
27
+ # notice, this list of conditions and the following disclaimer in the
28
+ # documentation and/or other materials provided with the distribution.
29
+ #
30
+ # * Neither the names of the copyright holder nor the names of its
31
+ # contributors may be used to endorse or promote products derived from
32
+ # this software without specific prior written permission.
33
+ #
34
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
36
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
38
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
+ #
46
+ # ######################################################################## #
47
+
48
+
49
+ =begin
50
+ =end
51
+
52
+ module Pantheios
53
+ module ApplicationLayer
54
+
55
+ module StockSeverityLevels
56
+
57
+ private
58
+ module Internal_
59
+
60
+ STOCK_SEVERITY_LEVELS_ = {
61
+
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 => [ 13, 'Trace' ],
75
+ }
76
+
77
+ def self.create_level_keys m
78
+
79
+ r = m.keys
80
+
81
+ m.each do |k, ar|
82
+
83
+ (ar[2] || []).each do |al|
84
+
85
+ r << al
86
+ end
87
+ end
88
+
89
+ r.uniq
90
+ end
91
+
92
+ def self.create_level_value_map m
93
+
94
+ r = {}
95
+
96
+ m.each do |s, ar|
97
+
98
+ warn 'invalid start-up' unless ::Symbol === s
99
+ warn 'invalid start-up' unless ::Array === ar
100
+
101
+ ([s] + (ar[2] || [])).each do |al|
102
+
103
+ r[al] = ar[0]
104
+ end
105
+ end
106
+
107
+ r
108
+ end
109
+ def self.create_level_string_map m
110
+
111
+ r = {}
112
+
113
+ m.each do |s, ar|
114
+
115
+ warn 'invalid start-up' unless ::Symbol === s
116
+ warn 'invalid start-up' unless ::Array === ar
117
+
118
+ ([s] + (ar[2] || [])).each do |al|
119
+
120
+ r[al] = ar[1]
121
+ end
122
+ end
123
+
124
+ r
125
+ end
126
+ end
127
+ public
128
+
129
+ # Ordered list of stock severity levels, without any aliases
130
+ STOCK_SEVERITY_LEVELS_PRIME = Internal_::STOCK_SEVERITY_LEVELS_.keys
131
+
132
+ # Ordered list of stock severity levels, some of which may be aliases
133
+ STOCK_SEVERITY_LEVELS = Internal_.create_level_keys Internal_::STOCK_SEVERITY_LEVELS_
134
+
135
+ # Mapping of severity levels (and level aliases) to integral
136
+ # equivalent
137
+ STOCK_SEVERITY_LEVEL_VALUES = Internal_.create_level_value_map Internal_::STOCK_SEVERITY_LEVELS_
138
+
139
+ # Mapping of severity levels (and level aliases) to string
140
+ STOCK_SEVERITY_LEVEL_STRINGS = Internal_.create_level_string_map Internal_::STOCK_SEVERITY_LEVELS_
141
+
142
+ end # module StockSeverityLevels
143
+
144
+ end # module ApplicationLayer
145
+ end # module Pantheios
146
+