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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
# ######################################################################## #
|
|
3
3
|
# File: lib/pantheios/services/simple_file_log_service.rb
|
|
4
4
|
#
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
# ::Pantheios::Services::SimpleFileLogService class
|
|
7
7
|
#
|
|
8
8
|
# Created: 17th June 2015
|
|
9
|
-
# Updated:
|
|
9
|
+
# Updated: 28th August 2026
|
|
10
10
|
#
|
|
11
|
-
# Home:
|
|
11
|
+
# Home: https://github.com/synesissoftware/Pantheios.Ruby
|
|
12
12
|
#
|
|
13
13
|
# Author: Matthew Wilson
|
|
14
14
|
#
|
|
15
|
-
# Copyright (c) 2019-
|
|
16
|
-
# Copyright (c) 2015-
|
|
15
|
+
# Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
|
|
16
|
+
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
|
17
17
|
# All rights reserved.
|
|
18
18
|
#
|
|
19
19
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -64,160 +64,159 @@ module Services
|
|
|
64
64
|
# +log(severity : Object, t : Time, prefix : String|Array, msg : String)+
|
|
65
65
|
class SimpleFileLogService
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
module SimpleFileLogService_Constants
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
DEFAULT_ROLL_DEPTH = 7
|
|
70
|
+
DEFAULT_ROLL_SIZE = 1024 * 1024
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
RECOGNISED_OPTIONS = %w{ roll_depth roll_period roll_size }.map { |s| s.to_sym }
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
end # module SimpleFileLogService_Constants
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
76
|
+
#
|
|
77
|
+
# === Signature
|
|
78
|
+
#
|
|
79
|
+
# * *Parameters:*
|
|
80
|
+
# - +log_file_or_path+:: [ +::File+, +::IO+, +::String+ ] A file or an
|
|
81
|
+
# IO that will be used as the target of the log statements, or a
|
|
82
|
+
# string specifying the path of the file to be used as the target
|
|
83
|
+
# - +options+:: [ ::Hash ] Options. Options other than those listed
|
|
84
|
+
# are ignored silently (except if +$DEBUG+, in which case a
|
|
85
|
+
# +warn+ing will be issued)
|
|
86
|
+
#
|
|
87
|
+
# * *Options:*
|
|
88
|
+
# - +:roll_period+:: ( +:daily+, +:weekly+, +:monthly+ ) The
|
|
89
|
+
# periodicity of the log-file rolling. Ignored unless
|
|
90
|
+
# +log_file_or_path+ is a +::String+. Ignored if either +:roll_size+
|
|
91
|
+
# or +:roll_depth+ is specified
|
|
92
|
+
# - +:roll_size+:: [ ::Integer, [ ::Integer, ::Integer ] ] An integer
|
|
93
|
+
# specifying the size of the log file, or an array containing the
|
|
94
|
+
# size of the log file and the depth of the log roll
|
|
95
|
+
# - +:roll_depth+:: [ ::Integer ] The depth of the size-based log
|
|
96
|
+
# rolling. Overrides the second element in an array specified for
|
|
97
|
+
# +:roll_size+
|
|
98
|
+
def initialize log_file_or_path, **options
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
roll_period = options[:roll_period]
|
|
101
|
+
roll_size = options[:roll_size]
|
|
102
|
+
roll_depth = options[:roll_depth]
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
if $DEBUG
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
options.each do |k, v|
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
warn "#{self.class}##{__method__}(): ignoring unrecognised option '#{k}'" unless SimpleFileLogService_Constants::RECOGNISED_OPTIONS.include?(:k)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
if roll_period && (roll_size || roll_depth)
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
warn "#{self.class}##{__method__}(): caller specified :roll_depth/:roll_period with :roll_size to #{self.class}##{__method__}() - ignoring :roll_period" if $DEBUG
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
roll_period = nil
|
|
117
|
+
end
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
if roll_size || roll_depth
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
if ::Array === roll_size
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
roll_size, d = roll_size
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
roll_depth ||= d
|
|
126
|
+
end
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
roll_size ||= SimpleFileLogService_Constants::DEFAULT_ROLL_SIZE
|
|
129
|
+
roll_depth ||= SimpleFileLogService_Constants::DEFAULT_ROLL_DEPTH
|
|
130
|
+
end
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
logger_init_options = {}
|
|
132
|
+
logger_init_args = []
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if false;
|
|
135
|
+
elsif roll_depth
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
logger_init_args << roll_depth
|
|
138
|
+
logger_init_args << roll_size
|
|
139
|
+
elsif roll_period
|
|
141
140
|
|
|
142
|
-
|
|
141
|
+
roll_period = roll_period.downcase.to_sym if ::String === roll_period
|
|
143
142
|
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
case roll_period
|
|
144
|
+
when :daily, :weekly, :monthly
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
;
|
|
147
|
+
else
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
raise ArgumentError, ":roll_period value must be one of :daily, :weekly, :monthly"
|
|
150
|
+
end
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
logger_init_args << roll_period.to_s
|
|
153
|
+
logger_init_args << 0
|
|
154
|
+
end
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
raise ArgumentError, ":roll_depth must be a non-negative integer" unless roll_depth.nil? || (::Integer === roll_depth && roll_depth >= 0)
|
|
157
|
+
raise ArgumentError, ":roll_size must be a non-negative integer" unless roll_size.nil? || (::Integer === roll_size && roll_size >= 0)
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
file_proc = lambda do
|
|
161
160
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
@logger = ::Logger.new log_file_or_path, *logger_init_args
|
|
162
|
+
@log_file_path = log_file_or_path.path
|
|
163
|
+
end
|
|
165
164
|
|
|
166
|
-
|
|
165
|
+
io_proc = lambda do
|
|
167
166
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
@logger = ::Logger.new log_file_or_path, *logger_init_args
|
|
168
|
+
@log_file_path = log_file_or_path.respond_to?(:path) ? log_file_or_path.path : nil
|
|
169
|
+
end
|
|
171
170
|
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
case log_file_or_path
|
|
172
|
+
when nil
|
|
174
173
|
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
raise ArgumentError, 'log_file_or_path may not be nil'
|
|
175
|
+
when ::IO#, ::StringIO
|
|
177
176
|
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
io_proc.call
|
|
178
|
+
when ::File#, ::Tempfile
|
|
180
179
|
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
file_proc.call
|
|
181
|
+
when ::String
|
|
183
182
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
@logger = ::Logger.new log_file_or_path, *logger_init_args
|
|
184
|
+
@log_file_path = log_file_or_path
|
|
185
|
+
else
|
|
187
186
|
|
|
188
|
-
|
|
187
|
+
ancestor_names = log_file_or_path.class.ancestors.map(&:to_s)
|
|
189
188
|
|
|
190
|
-
|
|
189
|
+
if false
|
|
191
190
|
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
;
|
|
192
|
+
elsif ancestor_names.include?('StringIO')
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
io_proc.call
|
|
195
|
+
elsif ancestor_names.include?('Tempfile')
|
|
197
196
|
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
file_proc.call
|
|
198
|
+
else
|
|
200
199
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
raise TypeError, "log_file_or_path type must be one of #{::File}, #{::IO}, #{::String}, #{::StringIO}"
|
|
201
|
+
end
|
|
202
|
+
end
|
|
204
203
|
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
self
|
|
205
|
+
end
|
|
207
206
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
# The path of the underlying log file. May return +nil+ if the path
|
|
208
|
+
# cannot be determined
|
|
209
|
+
attr_reader :log_file_path
|
|
211
210
|
|
|
212
|
-
|
|
211
|
+
def severity_logged? severity
|
|
213
212
|
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
true
|
|
214
|
+
end
|
|
216
215
|
|
|
217
|
-
|
|
216
|
+
def log sev, t, pref, msg
|
|
218
217
|
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
@logger << "#{pref}#{msg}\n"
|
|
219
|
+
end
|
|
221
220
|
end
|
|
222
221
|
|
|
223
222
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
# ######################################################################## #
|
|
3
3
|
# File: lib/pantheios/services/standard_log_service_adapter.rb
|
|
4
4
|
#
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
# ::Pantheios::Services::StandardLogServiceAdapter class
|
|
7
7
|
#
|
|
8
8
|
# Created: 18th June 2015
|
|
9
|
-
# Updated:
|
|
9
|
+
# Updated: 28th August 2026
|
|
10
10
|
#
|
|
11
|
-
# Home:
|
|
11
|
+
# Home: https://github.com/synesissoftware/Pantheios.Ruby
|
|
12
12
|
#
|
|
13
13
|
# Author: Matthew Wilson
|
|
14
14
|
#
|
|
15
|
-
# Copyright (c) 2019-
|
|
16
|
-
# Copyright (c) 2015-
|
|
15
|
+
# Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems
|
|
16
|
+
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
|
17
17
|
# All rights reserved.
|
|
18
18
|
#
|
|
19
19
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -68,176 +68,176 @@ module Services
|
|
|
68
68
|
# +log(severity : Object, t : Time, prefix : String|Array, msg : String)+
|
|
69
69
|
class StandardLogServiceAdapter
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
include ::Xqsr3::Quality::ParameterChecking
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
STOCK_SEVS_EXT2NUM = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
SEV_LEVELS_INT2PAIR = {
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
::Logger::DEBUG => [ :debug0, STOCK_SEVS_EXT2NUM[:debug0] ],
|
|
78
|
+
::Logger::WARN => [ :warning, STOCK_SEVS_EXT2NUM[:warning] ],
|
|
79
|
+
::Logger::ERROR => [ :failure, STOCK_SEVS_EXT2NUM[:failure] ],
|
|
80
|
+
::Logger::FATAL => [ :alert, STOCK_SEVS_EXT2NUM[:alert] ],
|
|
81
|
+
::Logger::UNKNOWN => [ :violation, STOCK_SEVS_EXT2NUM[:violation] ],
|
|
82
|
+
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
SEV_LEVELS_EXT2INT = {
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
:trace => ::Logger::DEBUG,
|
|
87
|
+
:benchmark => ::Logger::DEBUG,
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
:debug0 => ::Logger::DEBUG,
|
|
90
|
+
:debug1 => ::Logger::DEBUG,
|
|
91
|
+
:debug2 => ::Logger::DEBUG,
|
|
92
|
+
:debug3 => ::Logger::DEBUG,
|
|
93
|
+
:debug4 => ::Logger::DEBUG,
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
:notice => ::Logger::INFO,
|
|
96
|
+
:informational => ::Logger::INFO, :info => ::Logger::INFO,
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
:warning => ::Logger::WARN, :warn => ::Logger::WARN,
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
:failure => ::Logger::ERROR, :error => ::Logger::ERROR,
|
|
101
|
+
:critical => ::Logger::ERROR,
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
:alert => ::Logger::UNKNOWN,
|
|
104
|
+
:violation => ::Logger::UNKNOWN, :emergency => ::Logger::UNKNOWN,
|
|
105
|
+
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
SEV_LEVELS_EXT2NUM = {
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
STOCK_SEVS_EXT2NUM[:trace] => ::Logger::DEBUG,
|
|
110
|
+
STOCK_SEVS_EXT2NUM[:benchmark] => ::Logger::DEBUG,
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
STOCK_SEVS_EXT2NUM[:debug0] => ::Logger::DEBUG,
|
|
113
|
+
STOCK_SEVS_EXT2NUM[:debug1] => ::Logger::DEBUG,
|
|
114
|
+
STOCK_SEVS_EXT2NUM[:debug2] => ::Logger::DEBUG,
|
|
115
|
+
STOCK_SEVS_EXT2NUM[:debug3] => ::Logger::DEBUG,
|
|
116
|
+
STOCK_SEVS_EXT2NUM[:debug4] => ::Logger::DEBUG,
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
STOCK_SEVS_EXT2NUM[:notice] => ::Logger::INFO,
|
|
119
|
+
STOCK_SEVS_EXT2NUM[:informational] => ::Logger::INFO,
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
STOCK_SEVS_EXT2NUM[:warning] => ::Logger::WARN,
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
STOCK_SEVS_EXT2NUM[:failure] => ::Logger::ERROR,
|
|
124
|
+
STOCK_SEVS_EXT2NUM[:critical] => ::Logger::ERROR,
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
STOCK_SEVS_EXT2NUM[:alert] => ::Logger::UNKNOWN,
|
|
127
|
+
STOCK_SEVS_EXT2NUM[:violation] => ::Logger::UNKNOWN,
|
|
128
|
+
}
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
def initialize logger, adapter_threshold = nil, **options
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
check_parameter logger, 'logger', responds_to: [ :add, :level, :level= ]
|
|
134
|
+
check_parameter adapter_threshold, 'adapter_threshold', types: [ ::Integer, ::Symbol ], allow_nil: true
|
|
135
|
+
format = check_option options, :format, type: ::Symbol, values: [ :default, :simple, :standard ], allow_nil: true
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
@logger = logger
|
|
138
|
+
@format = format || :default
|
|
139
|
+
@adapter_threshold = adapter_threshold
|
|
140
|
+
@at_value = nil
|
|
141
|
+
@closed = false
|
|
142
|
+
end
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
# The threshold of the adapter, as expressed in a Pantheios severity
|
|
145
|
+
# level
|
|
146
|
+
#
|
|
147
|
+
# NOTE: may be +nil+, in which case the decision to determine whether to
|
|
148
|
+
# log (in the form of the +severity_logged?+ method) will be defered to
|
|
149
|
+
# the underlying logger.
|
|
150
|
+
attr_reader :adapter_threshold
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
def adapter_threshold= threshold
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
case @adapter_threshold = threshold
|
|
155
|
+
when nil
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
@at_value = nil
|
|
158
|
+
when ::Symbol
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
@at_value = STOCK_SEVS_EXT2NUM[threshold]
|
|
161
|
+
when ::Integer
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
@at_value = threshold
|
|
164
|
+
else
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
raise ::TypeError, 'adapter_threshold must be a symbol, an integer value, or nil'
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
def close
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
raise "already closed" if @closed
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
@logger.close
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
@closed = true
|
|
177
|
+
end
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
def flush
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
@logger.flush if @logger.respond_to? :flush
|
|
182
|
+
end
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
def severity_logged? severity
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
case severity
|
|
187
|
+
when nil
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
return true
|
|
190
|
+
when adapter_threshold
|
|
191
191
|
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
return true
|
|
193
|
+
when ::Symbol
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
sev = STOCK_SEVS_EXT2NUM[severity] || 0
|
|
196
|
+
when ::Integer
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
sev = severity
|
|
199
|
+
else
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
warn "severity - '#{severity}' - of invalid type (#{severity.class}) specified to severity_logged?"
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
return true
|
|
204
|
+
end
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
unless adapter_threshold
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
# ask the logger
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
_unused_sym, val = SEV_LEVELS_INT2PAIR[@logger.level]
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
return sev <= val
|
|
214
|
+
end
|
|
215
215
|
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
return sev <= @at_value
|
|
218
|
+
end
|
|
219
219
|
|
|
220
|
-
|
|
220
|
+
def log severity, t, prefix, msg
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
sev_ext = STOCK_SEVS_EXT2NUM[severity]
|
|
223
|
+
sev_ext ||= severity if ::Integer === severity
|
|
224
|
+
sev_int = SEV_LEVELS_EXT2NUM[sev_ext]
|
|
225
|
+
sev_int ||= ::Logger::UNKNOWN
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
case @format
|
|
228
|
+
when :default
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
prog_name = ::Pantheios::Util::ProcessUtil.derive_process_name $0
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
@logger.add sev_int, msg, prog_name
|
|
233
|
+
when :simple
|
|
234
234
|
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
@logger << msg + ?\n
|
|
236
|
+
when :standard
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
@logger << "#{prefix}#{msg}\n"
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
end # module Services
|
data/lib/pantheios/services.rb
CHANGED