module Pantheios::API
This inclusion module specifies the main logging API
methods, including:
as well as those that may be overridden:
-
severity_logged?
-
tracing?
-
severity_string
severity -
timestamp t
-
prefix
Public Instance Methods
Logs an arbitrary set of parameters at the given severity level
# File lib/pantheios/api.rb, line 81 def log severity, *args, &block return nil unless severity_logged? severity log_or_trace_with_block_ 1, severity, args, &block end
Logs an array of parameters at the given severity level
# File lib/pantheios/api.rb, line 89 def log_v severity, argv, &block return nil unless severity_logged? severity log_or_trace_with_block_ 1, severity, argv, &block end
Assembles the prefix_parts
into a string
-
Parameters:
-
t
[ Date, Time, DateTime ] The timestamp of the log entry -
severity
The severity
-
# File lib/pantheios/api.rb, line 263 def prefix t, severity prefix_parts(t, severity).join(', ') end
Defines the ordered list of log-statement elements
Elements¶ ↑
Elements can be one of:
- +:process_name+ - +:process_id+ - +:severity+ - +:thread_id+ - +:timestamp+
This is called from prefix
# File lib/pantheios/api.rb, line 171 def prefix_elements [ :process_name, :thread_id, :timestamp, :severity ] end
Assembles the prefix according to prefix_elements
into an array of parts
-
Parameters:
-
t
[ Date, Time, DateTime ] The timestamp of the log entry -
severity
The severity
-
# File lib/pantheios/api.rb, line 227 def prefix_parts t, severity prefix_elements.map do |el| case el when :program_name, :process_name process_name when :process_id process_id when :severity severity_string severity when :thread_id thread_id when :timestamp timestamp t else s = ::Symbol === el ? ":#{el}" : el.to_s warn "ignoring unrecognised prefix_element '#{s}'" nil end end end
Obtains the process id
Unless overridden, returns the value provided by ::Pantheios::Core::process_id
# File lib/pantheios/api.rb, line 180 def process_id ::Pantheios::Core.process_id end
Obtains the program name
Unless overridden, returns the value provided by ::Pantheios::Core::process_name
# File lib/pantheios/api.rb, line 189 def process_name ::Pantheios::Core.process_name end
Determines whether a given severity is logged
Signature¶ ↑
-
Parameters:
severity
-
The severity level, which should be a known log
severity symbol or an integral equivalent
-
Returns: a
truey
value if the severity should be logged; afalsey
value otherwise
# File lib/pantheios/api.rb, line 144 def severity_logged? severity ::Pantheios::Core.severity_logged? severity end
Obtains the string corresponding to the severity
Unless overridden, returns the value provided by ::Pantheios::Core::severity_string
# File lib/pantheios/api.rb, line 198 def severity_string severity ::Pantheios::Core.severity_string severity end
Obtains the thread id
Unless overridden, returns the value provided by ::Pantheios::Core::thread_id
# File lib/pantheios/api.rb, line 207 def thread_id ::Pantheios::Core.thread_id end
Obtains a string-form of the timestamp
Unless overridden, returns the value provided by ::Pantheios::Core::timestamp
# File lib/pantheios/api.rb, line 216 def timestamp t ::Pantheios::Core.timestamp t, nil end
Logs an arbitrary set of parameters at the Trace (:trace) level
# File lib/pantheios/api.rb, line 97 def trace *args, &block return nil unless tracing? trace_with_block_ 1, args, &block end
# File lib/pantheios/api.rb, line 124 def trace_b b, &block return nil unless tracing? ::Pantheios::Core.trace_v_impl(self, 1, ApplicationLayer::ParamNameList[*b.local_variables], :trace, b.local_variables.map { |lv| b.local_variable_get(lv) }, &block) end
# File lib/pantheios/api.rb, line 114 def trace_blv b, lvars, &block return nil unless tracing? ::Pantheios::Core.trace_v_impl(self, 1, ApplicationLayer::ParamNameList[*lvars], :trace, lvars.map { |lv| b.local_variable_get(lv) }, &block) end
Logs an array of parameters at the Trace (:trace) level
# File lib/pantheios/api.rb, line 105 def trace_v argv, &block return nil unless tracing? trace_with_block_ 1, argv, &block end
Determines whether tracing (severity == :trace) is enabled. This is used in the trace methods (trace
, trace_v
, trace_blv
, trace_b
) and therefore it may be overridden independently of severity_logged?
# File lib/pantheios/api.rb, line 152 def tracing? severity_logged? :trace end
Private Instance Methods
Private implementation method that should not need to be overridden
# File lib/pantheios/api.rb, line 279 def log_or_trace_with_block_ call_depth, severity, argv, &block if :trace == severity return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, severity, argv, &block end ::Pantheios::Core.log_v_impl self, severity, argv, &block end
# File lib/pantheios/api.rb, line 289 def trace_with_block_ call_depth, argv, &block return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, :trace, argv, &block end