0

我将 Rails 3.2.8 与 PostgreSQL/PostGIS 和 rgeo 系列宝石一起使用。这些会生成带有非常长查询的日志,这些查询很快就会变成 GB:

Region Load (8.8ms)  SELECT name, polygon FROM "region" WHERE "region"."id" = 17 LIMIT 1
(6.2ms)  SELECT st_astext(st_centroid('MULTIPOLYGON (((-111.1779942105267
64.09860899912356, -111.17799400000047 64.09859499912357, -111.17671900000042 
64.098605999123485, -111.17635518181078 64.09860899912356, -111.17538500000043  
...
...many, many, many points ...
...
-111.17799600000035 64.101920999123465, -111.1779940000004 64.10127099912361,
-111.17799500000035 64.09935199912358, -111.17799600000035 64.09872799912365,
-111.1779942105267 64.09860899912356)))'))

是否有内置方法来限制 Rails 日志条目的长度?对于某些类型的查询(即本例中的地理查询),更好的方法是仅限制日志的查询部分。

4

1 回答 1

1

非常简单,这是(修改后的)Railscast

# config/initializers/log_formatter.rb
class Logger::SimpleFormatter
  def call(severity, time, progname, msg)
    "[#{severity}] #{msg.truncate(200)}\n"
  end
end
于 2012-10-11T19:40:24.457 回答