module Ramaze::Logging

This module provides a basic skeleton for your own loggers to be compatible.

@example

class MyLogger
  include Logging

  def log(tag, *args)
    p tag => args
  end
end

Public Instance Methods

<<(*objects)
Alias for: debug
debug(*objects) click to toggle source

Inspects objects if they are no strings. Tag is :debug

@param [Array] objects An array of objects that will be inspected.

# File lib/ramaze/log/logging.rb, line 60
def debug(*objects)
  tag_log(:debug, :inspect, *objects)
end
Also aliased as: <<
debug?() click to toggle source

Stub for WEBrick

# File lib/ramaze/log/logging.rb, line 103
def debug?
  false
end
dev(*objects) click to toggle source

Inspects objects if they are no strings. Tag is :dev

@param [Array] objects An array of objects that will be inspected.

# File lib/ramaze/log/logging.rb, line 69
def dev(*objects)
  tag_log(:dev, :inspect, *objects)
end
error(ex) click to toggle source

Takes either an Exception or just a String, formats backtraces to be a bit more readable and passes all of this on to #tag_log :error

@param [Object] ex The exception that was raised.

# File lib/ramaze/log/logging.rb, line 81
def error(ex)
  if ex.respond_to?(:exception)
    message = ex.backtrace
    message.map!{|m| m.to_s.gsub(/^#{Regexp.escape(Dir.pwd)}/, '.') }
    message.unshift(ex.inspect)
  else
    message = ex.to_s
  end
  tag_log(:error, :to_s, *message)
end
info(*objects) click to toggle source

Converts everything given to strings and passes them on with :info

@param [Array] objects An array of objects that need to be converted to

strings.
# File lib/ramaze/log/logging.rb, line 41
def info(*objects)
  tag_log(:info, :to_s, *objects)
end
shutdown() click to toggle source

Nothing.

THINK: Is this really required? It doesn't do anything anyway.

# File lib/ramaze/log/logging.rb, line 97
def shutdown
end
tag_log(tag, meth, *msgs) click to toggle source

Takes the tag (:warn|:debug|:error|:info) and the name of a method to be called upon elements of msgs that don't respond to :to_str Goes on and sends the tag and transformed messages each to the log method. If you include this module you have to define log or it will raise.

@param [String] tag The level of the log message. @param [String] meth @param [Array] msgs The data that should be logged.

# File lib/ramaze/log/logging.rb, line 28
def tag_log(tag, meth, *msgs)
  msgs.each do |msg|
    string = (msg.respond_to?(:to_str) ? msg : msg.send(meth))
    log(tag, string)
  end
end
warn(*objects) click to toggle source

Converts everything given to strings and passes them on with :warn

@param [Array] objects An array of objects that need to be converted to

strings.
# File lib/ramaze/log/logging.rb, line 51
def warn(*objects)
  tag_log(:warn, :to_s, *objects)
end