Class: Pantheios::Services::MultiplexingLogService

Inherits:
Object
  • Object
show all
Defined in:
lib/pantheios/services/multiplexing_log_service.rb

Overview

A class that fulfils the Pantheios LogService protocol by multiplexing its responsibilities to a number of (concrete) log service instances

NOTE: The LogService protocol is implemented by a class that provides the instance methods severity_logged?(severity : Object) : boolean and log(severity : Object, t : Time, prefix : String|Array, msg : String)

Instance Method Summary collapse

Constructor Details

#initialize(services, **options) ⇒ MultiplexingLogService

Initializes the instance with an array of log services, according to the given options

Signature

  • Parameters:

    • services
      ::Array

      An array of instances that observe the

      Log Service protocol

    • options
      ::Hash

      options

  • Options:

    • :level_cache_mode
      ::Symbol

      Specifies the mode of severity

      level caching, and must be one of the following values:

      • :none

        no severity level caching is performed. This is the

        default because it is completely thread-safe, but it is the slowest mode, and users are advised to specify another mode suitable to their use

      • :thread_fixed

        remembers the response of each multiplexed log

        service to each severity level on a thread-specific basis

      • :process_fixed

        remembers the response of each multiplexed

        log service to each severity level and then remembers that for the duration of the lifetime of the instance

    • :unsync_process_lcm
      boolean

      If truey, causes

      :process_fixed :level_cache_mode to NOT be synchronised; the default is for it to be synchronised using an internal Mutex instance



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pantheios/services/multiplexing_log_service.rb', line 103

def initialize services, **options

	@tss_sym	=	self.to_s.to_sym
	@services	=	services.map { |svc| MultiplexingLogService_Internals_::ServiceManagementInfo.new svc }
	@options	=	options.dup
	@mode		=	options[:level_cache_mode]
	@unsync_pf	=	options[:unsync_process_lcm]

	@process_m	=	{}
	@mx			=	Mutex.new unless @unsync_pf
end

Instance Method Details

#log(sev, t, pref, msg) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/pantheios/services/multiplexing_log_service.rb', line 239

def log sev, t, pref, msg

	tss_m	=	:thread_fixed == @mode ? get_tss_svc_sev_map_ : nil

	@services.each do |smi|

		svc	=	smi.service

		case @mode
		when :process_fixed

			if @unsync_pf

				isl	=	svc_sev_logged_pf_ @process_m, svc, sev
			else

				isl	=	@mx.synchronize { svc_sev_logged_pf_ @process_m, svc, sev }
			end
		when :thread_fixed

			m	=	tss_m

			isl	=	svc_sev_logged_tf_ m, svc, sev
		else # :none

			isl	=	svc.severity_logged? sev
		end


		svc.log sev, t, pref, msg if isl
	end
end

#requires_prefix?Boolean

Indicates whether any of the services require a prefix and, if so, what it may require

Return

(false, true, :parts) An indicator what the most needy of the multiplexed services requires

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/pantheios/services/multiplexing_log_service.rb', line 178

def requires_prefix?

	return @requires_prefix unless @requires_prefix.nil?

	requires_prefix = false

	@services.each do |svc|

		if svc.respond_to? :requires_prefix?

			case rp = svc.requires_prefix?
			when nil, false

				;
			when true

				requires_prefix ||= true
			when :parts

				requires_prefix = rp
				break
			else

				warn "unrecognised return from requires_prefix? for service #{svc}: #{rp} (#{rp.class})"
			end
		end
	end

	@requires_prefix = requires_prefix
end

#severity_logged?(severity) ⇒ Boolean

Indicates whether the given severity is to be logged by any of the multiplexed log services

Returns:

  • (Boolean)


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/pantheios/services/multiplexing_log_service.rb', line 211

def severity_logged? severity

	case @mode
	when :process_fixed

		if @unsync_pf

			sev_logged_pf_ @process_m, severity
		else

			@mx.synchronize { sev_logged_pf_ @process_m, severity }
		end
	when :thread_fixed

		m	=	get_tss_svc_sev_map_

		@services.any? do |smi|

			svc	=	smi.service

			svc_sev_logged_tf_ m, svc, severity
		end
	else # :none

		@services.any? { |smi| smi.service.severity_logged? severity }
	end
end