为什么rails会记录空行?

时间:2012-03-06 12:04:35

标签: ruby-on-rails-3 logging

如果我在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 ...

1 个答案:

答案 0 :(得分:0)

我认为它与this changeinternet archive backup)有关,试图允许在某种程度上保护资产日志消息。