Module: Pantheios::Core
- Defined in:
- lib/pantheios/core.rb
Defined Under Namespace
Modules: Constants_, Internals_
Class Method Summary collapse
-
.core_init ⇒ Object
:nodoc:.
-
.get_block_value_(&block) ⇒ Object
Internal implementation method, not to be called by application code.
-
.included(receiver) ⇒ Object
module Internals_.
-
.log_raw(prefix_provider, severity, message) ⇒ Object
Internal implementation method, not to be called by application code.
-
.log_v_impl(prefix_provider, severity, argv, &block) ⇒ Object
Internal implementation method, not to be called by application code.
-
.process_id ⇒ Object
Default implementation to obtain the process id.
-
.process_name ⇒ Object
Default implementation to obtain the process name.
-
.process_name=(name) ⇒ Object
Sets the process name.
-
.program_name ⇒ Object
- DEPRECATED
-
Use
process_name.
-
.program_name=(name) ⇒ Object
- DEPRECATED
-
Use
process_name=.
-
.register_include(includee, includer) ⇒ Object
:nodoc:.
-
.set_back_end(be) ⇒ Object
Sets the back-end used to emit the given log statement.
-
.set_default_service(**options) ⇒ Object
:nodoc:.
-
.set_front_end(fe) ⇒ Object
Sets the front-end that will be used to evaluate whether a given log statement will be logged.
-
.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.
-
.severity_logged?(severity) ⇒ Boolean
Default implementation to determine whether the given severity is logged.
-
.severity_string(severity) ⇒ Object
Obtains a string form of the given severity.
-
.thread_id ⇒ Object
Default implementation to obtain the thread_id.
-
.timestamp(t, fmt) ⇒ Object
Default implementation to obtain the timestamp according to a given format.
- .timestamp_format ⇒ Object
-
.trace_v_impl(prefix_provider, call_depth, param_list, severity, argv, &block) ⇒ Object
Internal implementation method, not to be called by application code.
Class Method Details
.core_init ⇒ Object
:nodoc:
208 209 210 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 238 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 271 272 273 274 275 276 277 |
# File 'lib/pantheios/core.rb', line 208 def self.core_init # process-name prg_nam = nil case Pantheios::Globals.PROCESS_NAME when nil ; when ::Symbol prg_nam = ::Pantheios::Util::ProcessUtil.derive_process_name $0, style: Pantheios::Globals.PROCESS_NAME when ::String prg_nam = Pantheios::Globals.PROCESS_NAME.strip prg_nam = nil if prg_name.empty? else warn "ignoring unsupported Globals.PROCESS_NAME type - '#{Pantheios::Globals.PROCESS_NAME.class}'" end @process_name = prg_nam if prg_nam # main thread-name # # This is obtained from Pantheios::Globals.MAIN_THREAD_NAME, which # may be either ::String or [ ::String, ::Thread ] mt_th = nil mt_nam = nil case pg_mtn = ::Pantheios::Globals.MAIN_THREAD_NAME when nil ; when ::Array if pg_mtn.size != 2 warn "ignoring array of wrong length - #{pg_mtn.size} given; 2-required - for Globals.MAIN_THREAD_TYPE" else mt_th = pg_mtn[0] mt_nam = pg_mtn[1] if ::Thread === mt_nam mt_th, mt_nam = mt_nam, mt_th end end when ::String mt_th = Thread.current mt_nam = pg_mtn else warn "ignoring unsupported Globals.MAIN_THREAD_NAME type - '#{Pantheios::Globals.MAIN_THREAD_NAME.class}'" end ::Pantheios::Util::ThreadUtil.set_thread_name mt_th, mt_nam if mt_nam # state (incl. default service) @@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
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/pantheios/core.rb', line 465 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_
202 203 204 205 |
# File 'lib/pantheios/core.rb', line 202 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
593 594 595 596 597 598 599 600 |
# File 'lib/pantheios/core.rb', line 593 def self.log_raw prefix_provider, severity, now = Time.now prf = @@state.requires_prefix? ? '[' + prefix_provider.prefix(now, severity) + ']: ' : nil @@state.back_end.log severity, now, prf, end |
.log_v_impl(prefix_provider, severity, argv, &block) ⇒ Object
Internal implementation method, not to be called by application code
489 490 491 492 493 494 |
# File 'lib/pantheios/core.rb', line 489 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_id ⇒ Object
Default implementation to obtain the process id
-
Returns:
Process.pid
377 378 379 380 |
# File 'lib/pantheios/core.rb', line 377 def self.process_id Process.pid end |
.process_name ⇒ Object
Default implementation to obtain the process name
-
Returns: The file stem of $0
NOTE: this is implemented in terms of Process_Util.derive_process_name and the result is cached
389 390 391 392 |
# File 'lib/pantheios/core.rb', line 389 def self.process_name @process_name ||= ::Pantheios::Util::ProcessUtil.derive_process_name $0 end |
.process_name=(name) ⇒ Object
Sets the process name
-
Parameters:
name- String
-
The (new) process name. May be
nil, in which
case
process_namewill obtain the process name fromProcess_Util.derive_process_name -
Returns: The previous version
NOTE: to reset the value, set to nil
408 409 410 411 412 413 |
# File 'lib/pantheios/core.rb', line 408 def self.process_name= name previous, @process_name = @process_name, name previous end |
.program_name ⇒ Object
- DEPRECATED
-
Use
process_name
395 |
# File 'lib/pantheios/core.rb', line 395 def self.program_name; self.process_name; end |
.program_name=(name) ⇒ Object
- DEPRECATED
-
Use
process_name=
416 |
# File 'lib/pantheios/core.rb', line 416 def self.program_name= name; self.process_name = name; end |
.register_include(includee, includer) ⇒ Object
:nodoc:
355 356 357 358 |
# File 'lib/pantheios/core.rb', line 355 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:
-
beThe back-end instance. It must respond to thelogmessage, or a ::TypeError will be raised. It may also respond to therequires_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
nilif no previous one was registered
328 329 330 331 |
# File 'lib/pantheios/core.rb', line 328 def self.set_back_end be @@state.set_back_end be end |
.set_default_service(**options) ⇒ Object
:nodoc:
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/pantheios/core.rb', line 280 def self.set_default_service ** # determine which log service to initialise as the default ([::Pantheios::Globals.INITIAL_SERVICE_INSTANCES].flatten || []).reject(&:nil?).each do |inst| next unless inst return @@state.set_service inst end ([::Pantheios::Globals.INITIAL_SERVICE_CLASSES].flatten || []).reject(&:nil?).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:
-
feThe front-end instance. It must respond to theseverity_logged?message, or a ::TypeError will be raised
-
-
Returns: The previously registered instance, or
nilif no previous one was registered
311 312 313 314 |
# File 'lib/pantheios/core.rb', line 311 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:
-
svcThe service instance. It must respond to theseverity_logged?andlogmessages, or a ::TypeError will be raised. It may also respond to therequires_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
347 348 349 350 |
# File 'lib/pantheios/core.rb', line 347 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 returnstrue- all statements are emitted in debug mode. In normal operation, if the integral value ofseverityis greater than that of:informationalthen it returnsfalse; otherwise it returntrue
368 369 370 371 |
# File 'lib/pantheios/core.rb', line 368 def self.severity_logged? severity @@state.severity_logged? severity end |
.severity_string(severity) ⇒ Object
Obtains a string form of the given severity
419 420 421 422 423 424 |
# File 'lib/pantheios/core.rb', line 419 def self.severity_string severity r = ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[severity] and return r severity.to_s end |
.thread_id ⇒ Object
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 viaobject_id
431 432 433 434 435 436 437 438 |
# File 'lib/pantheios/core.rb', line 431 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. Ifnilthe value obtained bytimestamp_formatis used -
Returns: A string representing the time
455 456 457 458 459 460 |
# File 'lib/pantheios/core.rb', line 455 def self. t, fmt fmt ||= self. t.strftime fmt end |
.timestamp_format ⇒ Object
440 441 442 443 |
# File 'lib/pantheios/core.rb', line 440 def self. '%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
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/pantheios/core.rb', line 497 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 |