class GenericMonitorLog

This class provides a generic and simple way to log ruby code.

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source

The class constructor.

# File lib/gml/generic_monitor_log.rb, line 13
def initialize(options = {})
  raise StandardError.new("'options' must be a Hash or nil.") if !options.is_a?(Hash)

  @options = DEFAULT_OPTIONS.merge(options)
end

Public Instance Methods

entry(log_level = Gml::LOG_LEVEL_INFO, log_entry = "", caller_depth = 1) click to toggle source

The main method that logs the messages.

# File lib/gml/generic_monitor_log.rb, line 22
def entry(log_level = Gml::LOG_LEVEL_INFO, log_entry = "", caller_depth = 1)
  if ((log_level <= @options[:log_level]) && (@options[:console] || @options[:output]))
    at = caller_locations()[caller_depth]
    out =   "[#{Time.now.strftime(@options[:time_format])}] #{Gml::LOG_STRINGS[log_level]} "
    out <<  "[#{File.basename(at.absolute_path)}->#{at.label}: #{at.lineno}]"
    out <<  " - " if log_entry.size > 0
    out <<  log_entry

    @options[:console].puts(out) if @options[:console]

    if (@options[:output])
      if (@options[:output].is_a?(IO))
        @options[:output].puts(out)

      else
        out << "\n"
        File.write(@options[:output], out, (File.exist?(@options[:output]) ? File.size(@options[:output]) : 0))
      end

    end

  end
end
log(log_entry = "")
Alias for: log_info
log_debug(log_entry = "") click to toggle source

Log a debug message. This is a convenience method.

# File lib/gml/generic_monitor_log.rb, line 72
def log_debug(log_entry = "")
  entry(Gml::LOG_LEVEL_DEBUG, log_entry, 1)
end
log_info(log_entry = "") click to toggle source

Log an info message. This is a convenience method.

# File lib/gml/generic_monitor_log.rb, line 56
def log_info(log_entry = "")
  entry(Gml::LOG_LEVEL_INFO, log_entry, 1)
end
Also aliased as: log
log_panic(log_entry = "") click to toggle source

Log a panic message. This is a convenience method.

# File lib/gml/generic_monitor_log.rb, line 49
def log_panic(log_entry = "")
  entry(Gml::LOG_LEVEL_PANIC, log_entry, 1)
end
log_trace(log_entry = "") click to toggle source

Log a trace message. This is a convenience method.

# File lib/gml/generic_monitor_log.rb, line 79
def log_trace(log_entry = "")
  entry(Gml::LOG_LEVEL_TRACE, log_entry, 1)
end
log_verbose(log_entry = "") click to toggle source

Log a verbose message. This is a convenience method.

# File lib/gml/generic_monitor_log.rb, line 65
def log_verbose(log_entry = "")
  entry(Gml::LOG_LEVEL_VERBOSE, log_entry, 1)
end