Module: Pantheios::Core

Defined in:
lib/pantheios/core.rb

Defined Under Namespace

Modules: Constants_, Internals_

Class Method Summary collapse

Class Method Details

.core_initObject

:nodoc:



200
201
202
203
204
205
# File 'lib/pantheios/core.rb', line 200

def self.core_init

	@@state = Internals_::State.new Internals_::DefaultDiscriminator.new

	self.set_default_service
end

.get_block_value_(&block) ⇒ Object

Internal implementation method, not to be called by application code



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/pantheios/core.rb', line 368

def self.get_block_value_ &block

	case block.arity
	when 0

		yield
	when 1

		yield severity
	when 2

		yield severity, argv
	when 3

		yield severity, argv, self
	else

		warn 'too many parameters in logging block'

		yield severity, argv, self
	end
end

.included(receiver) ⇒ Object

module Internals_



194
195
196
197
# File 'lib/pantheios/core.rb', line 194

def self.included receiver

	abort "Attempt to include #{self} into #{receiver}. This is not allowed"
end

.log_raw(prefix_provider, severity, message) ⇒ Object

Internal implementation method, not to be called by application code



496
497
498
499
500
501
502
503
# File 'lib/pantheios/core.rb', line 496

def self.log_raw prefix_provider, severity, message

	now	=	Time.now

	prf	=	@@state.requires_prefix? ? '[' + prefix_provider.prefix(now, severity) + ']: ' : nil

	@@state.back_end.log severity, now, prf, message
end

.log_v_impl(prefix_provider, severity, argv, &block) ⇒ Object

Internal implementation method, not to be called by application code



392
393
394
395
396
397
# File 'lib/pantheios/core.rb', line 392

def self.log_v_impl prefix_provider, severity, argv, &block

	argv << get_block_value_(&block) if block_given?

	self.log_raw prefix_provider, severity, argv.join
end

.process_idObject

Default implementation to obtain the process id

  • Returns: Process.pid



305
306
307
308
# File 'lib/pantheios/core.rb', line 305

def self.process_id

	Process.pid
end

.program_nameObject

Default implementation to obtain the program name

  • Returns: The file stem of $0

NOTE: this is implemented in terms of Process_Util.derive_process_name and the result is cached



317
318
319
320
# File 'lib/pantheios/core.rb', line 317

def self.program_name

	@program_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0
end

.register_include(includee, includer) ⇒ Object

:nodoc:



283
284
285
286
# File 'lib/pantheios/core.rb', line 283

def self.register_include includee, includer

	$stderr.puts "#{includee} included into #{includer}" if $DEBUG
end

.set_back_end(be) ⇒ Object

Sets the back-end used to emit the given log statement

  • Parameters:

    • be The back-end instance. It must respond to the log message, or a ::TypeError will be raised. It may also respond to the requires_prefix? message, which can be used to indicate whether a prepared prefix is required; if not present, the framework assumes that the back-end requires a prefix

  • Returns: The previously registered instance, or nil if no previous one was registered



256
257
258
259
# File 'lib/pantheios/core.rb', line 256

def self.set_back_end be

	@@state.set_back_end be
end

.set_default_service(**options) ⇒ Object

:nodoc:



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/pantheios/core.rb', line 208

def self.set_default_service **options

	# determine which log service to initialise as the default

	(::Pantheios::Globals.INITIAL_SERVICE_INSTANCES || []).each do |inst|

		next unless inst

		return @@state.set_service inst
	end

	(::Pantheios::Globals.INITIAL_SERVICE_CLASSES || []).each do |cls|

		inst = cls.new

		return @@state.set_service inst
	end

	@@state.set_service ::Pantheios::Services::SimpleConsoleLogService.new
end

.set_front_end(fe) ⇒ Object

Sets the front-end that will be used to evaluate whether a given log statement will be logged

  • Parameters:

    • fe The front-end instance. It must respond to the severity_logged? message, or a ::TypeError will be raised

  • Returns: The previously registered instance, or nil if no previous one was registered



239
240
241
242
# File 'lib/pantheios/core.rb', line 239

def self.set_front_end fe

	@@state.set_front_end fe
end

.set_service(svc) ⇒ Object

Sets the service that will be used to evaluate whether a given log statement will be logged and to emit it

  • Parameters:

    • svc The service instance. It must respond to the severity_logged? and log messages, or a ::TypeError will be raised. It may also respond to the requires_prefix? message, which can be used to indicate whether a prepared prefix is required; if not present, the framework assumes that the service (back-end) requires a prefix

  • Returns: An array of two elements, representing the previous front-end and previous back-end



275
276
277
278
# File 'lib/pantheios/core.rb', line 275

def self.set_service svc

	@@state.set_service svc
end

.severity_logged?(severity) ⇒ Boolean

Default implementation to determine whether the given severity is logged

  • Returns: If $DEBUG is true, then returns true - all statements are emitted in debug mode. In normal operation, if the integral value of severity is greater than that of :informational then it returns false; otherwise it return true

Returns:

  • (Boolean)


296
297
298
299
# File 'lib/pantheios/core.rb', line 296

def self.severity_logged? severity

	@@state.severity_logged? severity
end

.severity_string(severity) ⇒ Object



322
323
324
325
326
327
# File 'lib/pantheios/core.rb', line 322

def self.severity_string severity

	r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r

	severity.to_s
end

.thread_idObject

Default implementation to obtain the thread_id

  • Returns: From the current thread either the value obtained via the attribute thread_name (if it responds to that) or via object_id



334
335
336
337
338
339
340
341
# File 'lib/pantheios/core.rb', line 334

def self.thread_id

	t = Thread.current

	return t.thread_name if t.respond_to? :thread_name

	t.object_id
end

.timestamp(t, fmt) ⇒ Object

Default implementation to obtain the timestamp according to a given format

  • Parameters:

  • t [::Time] The time

  • fmt [::String, nil] The format to be used. If nil the value obtained by timestamp_format is used

  • Returns: A string representing the time



358
359
360
361
362
363
# File 'lib/pantheios/core.rb', line 358

def self.timestamp t, fmt

	fmt ||= self.timestamp_format

	t.strftime fmt
end

.timestamp_formatObject



343
344
345
346
# File 'lib/pantheios/core.rb', line 343

def self.timestamp_format

	'%Y-%m-%d %H:%M:%S.%6N'
end

.trace_v_impl(prefix_provider, call_depth, param_list, severity, argv, &block) ⇒ Object

Internal implementation method, not to be called by application code



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/pantheios/core.rb', line 400

def self.trace_v_impl prefix_provider, call_depth, param_list, severity, argv, &block

	unless param_list

		if ApplicationLayer::ParamNameList === argv[0]

			param_list	=	argv.shift
		end
	end

	if block_given?

		br = get_block_value_ &block

		if ApplicationLayer::ParamNameList === br

			param_list	=	br
		else
			if ::Array === br

				if ApplicationLayer::ParamNameList === br[0]

					param_list	=	br.shift
				end

				argv += br
			else

				argv << br
			end
		end
	end

	case param_list
	when nil
		;
	when ApplicationLayer::ParamNameList
		;
	else

		warn "param_list (#{param_list.class}) must be nil or an instance of #{ApplicationLayer::ParamNameList}" unless param_list
	end

	fl	=	nil
	rx	=	nil
	fn	=	caller(call_depth + 1, 1)[0]

	if ::Class === prefix_provider

		rx	=	"#{prefix_provider}::"
	else

		rx	=	"#{prefix_provider.class}#"
	end

	if false;
	elsif fn =~ /(.+)\:in\s*\`(.+)\'\s*$/

		fl	=	$1
		fn	=	$2

		f	=	"#{fl}: #{rx}#{fn}"
	elsif fn =~ /.*in\s*\`(.+)\'\s*$/

		f	=	$1
	else

		f	=	fn
	end

	if param_list

		sig = ''

		argv.each_with_index do |arg, index0|

			n	=	param_list[index0]

			s	=	arg.to_s
			s	=	"'#{s}'" if s.index(/[,\s]/)

			sig	+=	', ' unless sig.empty?

			sig	+=	n ? "#{n} (#{arg.class})=#{s}" : s
		end
	else

		sig = argv.join(', ')
	end

	stmt = "#{f}(#{sig})"

	self.log_raw prefix_provider, severity, stmt
end