简体   繁体   中英

Logstash-logger: Rails stacktrace splitting into multiple json lines

I'm using logstash-logger to log my rails logs. It works for most cases, but when something goes wrong (ie; I get an error) Rails produces a stack trace. But the logger logs it into multiple Json lines. How can I solve this?

I'm attaching a small part of the log here

{"message":"Started GET \\"/\\" ... }

{"message":" ", ... }

{"message":"ActionController::RoutingError (No route matches [GET] \\"/\\"):" ... }

{"message":"vendor/bundle/ruby/2 ... }

This is single stack trace, but the logger is logging it as multiple logs.

This is my logstash-logger configuration

logstash_logger = LogStashLogger.new(
  type: :file,
  path: "log/#{Rails.env}.log",
  sync: true
)
if "#{Rails.env}" != "development"
  config.logger = logstash_logger
end

Custom Log Fields

LogStashLogger by default will log a JSON object with the format below.

{
  "message":"Some Message",
  "@timestamp":"2015-01-29T10:43:32.196-05:00",
  "@version":"1",
  "severity":"INFO",
  "host":"hostname"
}

then I read

Rails Integration

Supports Rails 4 and 5.

By default, every Rails log message will be written to logstash in LogStash::Event JSON format.

For minimal, more-structured logstash events, try one of the following gems:

lograge

yarder

Currently these gems output a JSON string, which LogStashLogger then parses. Future versions of these gems could potentially have deeper integration with LogStashLogger (eg by directly writing LogStash::Event objects).

Did you dig deep in this documentation because they do on purpose give you a json format

要以多行的json格式获取 rails 日志,您应该使用type: :json_lines

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM