Railsでの値追跡

perl だと「warn」を使用すればApacheのerror_logに値が出力されるのですが
rubyでそれにあたるものは何だろうかと思い調べてみた。
(値をセッションに突っ込んでしまえば終わりな気もしますが)

どうもloggerをrequireしてしまえばよいらしい。

本家のページには以下のように記述されていた。

Logger.new(name, shift_age = 7, shift_size = 1048576)

最初のページと引数が違うなとおもったので直下を見たら
以下のようになっていた。
確かに、「log」をとるなら必要な情報だよなと思い納得。

logdev: The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).
shift_age: Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).
shift_size: Maximum logfile size (only applies when shift_age is a number).


出力する方法が以下のように書かれていたので

$logger.debug 'some debug message (in ' + self.class.to_s + ')'

直接見てみると、

debugの所で「See info for more information.」といわれた。
で、中身見てみると構造一緒だった。

debug

def debug(progname = nil, &block)
add(DEBUG, nil, progname, &block)
end

info

def info(progname = nil, &block)
add(INFO, nil, progname, &block)
end

で、以下の一文を見て納得した。hoge

Log a message if the given severity is high enough. This is the generic logging method. Users will be more inclined to use debug, info, warn, error, and fatal.


参照:
http://www.machu.jp/diary/20040408.html
http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/classes/Logger.html