Logger API: Module OverSIP::Logger

The Logger API lets the user to log custom messages to Syslog via the OverSIP::Logger Ruby module. Such a module must be included into the user’s custom modules/classes if the user wants to log custom messages from those modules/classes.

Module class and instance methods

The OverSIP::Logger module provides the following methods which log the given message to Syslog with different severity values:

  • User logging:
    • log_debug(message)
    • log_info(message)
    • log_notice(message)
    • log_warn(message)
    • log_error(message)
    • log_crit(message)
    • log_alert(message)
    • log_emerg(message)
  • System/modules logging:
    • log_system_debug(message)
    • log_system_info(message)
    • log_system_notice(message)
    • log_system_warn(message)
    • log_system_error(message)
    • log_system_crit(message)
    • log_system_alert(message)
    • log_system_emerg(message)

Parameters

message
The message to log. It can be a String or an Exception object.

Usage

The custom Ruby module or class defined by the user must include or extend the OverSIP::Logger module:

  • include makes the OverSIP::Logger module’s methods available to every instance of the user defined class (becoming “instance methods”).
  • extend makes the OverSIP::Logger module’s methods available to the class/module itself (becoming “class methods”).

Example code

module MyApp

  extend OverSIP::Logger

  # Module method.
  def hello
    log_info "logging from a class method"
  end

  class MyClass

    include OverSIP::Logger

    # Class instance method.
    def hello
      log_info "logging from an instance method"
    end

  end

end