module Pantheios::API

This inclusion module specifies the main logging API methods, including:

as well as those that may be overridden:

Public Instance Methods

log(severity, *args, &block) click to toggle source

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
log_v(severity, argv, &block) click to toggle source

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
prefix(t, severity) click to toggle source

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
prefix_elements() click to toggle source

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
prefix_parts(t, severity) click to toggle source

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
process_id() click to toggle source

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
process_name() click to toggle source

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
severity_logged?(severity) click to toggle source

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; a falsey value otherwise

# File lib/pantheios/api.rb, line 144
def severity_logged? severity

        ::Pantheios::Core.severity_logged? severity
end
severity_string(severity) click to toggle source

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
thread_id() click to toggle source

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
timestamp(t) click to toggle source

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
trace(*args, &block) click to toggle source

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
trace_b(b, &block) click to toggle source
# 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
trace_blv(b, lvars, &block) click to toggle source
# 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
trace_v(argv, &block) click to toggle source

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
tracing?() click to toggle source

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

log_or_trace_with_block_(call_depth, severity, argv, &block) click to toggle source

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
trace_with_block_(call_depth, argv, &block) click to toggle source
# 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