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.
-
.program_name ⇒ Object
Default implementation to obtain the program 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
-
.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:
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, 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
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_id ⇒ Object
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_name ⇒ Object
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:
-
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
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 ** # 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:
-
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
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:
-
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
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 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
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_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
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. Ifnilthe value obtained bytimestamp_formatis used -
Returns: A string representing the time
358 359 360 361 362 363 |
# File 'lib/pantheios/core.rb', line 358 def self. t, fmt fmt ||= self. t.strftime fmt end |
.timestamp_format ⇒ Object
343 344 345 346 |
# File 'lib/pantheios/core.rb', line 343 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
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 |