如果我在Rails中格式化日志消息,我经常会得到一个空行。例如:
Started GET "/assets/jquery.ifixpng.js?body=1" for 127.0.0.1 at 2012-03-06 12:59:43 +0100
2012-03-06 12:59:43 INFO Served asset /jquery.ifixpng.js - 200 OK (26ms)
2012-03-06 12:59:43 INFO
Started GET "/assets/logo.png" for 127.0.0.1 at 2012-03-06 12:59:43 +0100
2012-03-06 12:59:43 INFO Served asset /logo.png - 200 OK (26ms)
2012-03-06 12:59:43 INFO
自定义format_message
class Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
如何摆脱像2012-03-06 12:59:43 INFO?
这样的空行我已经检查了msg.empty?还是msg.nil?但没有任何成功。我还检查了\ n或\ r或\ n \ n或\ r \ n \ r \ n ...