logstasher: Adding custom fields to the log is not working with rails 3.2.13

Adding custom fields to the log is not working with rails 3.2.13 and logstasher 0.2.5. I have followed all the step and created a file as config/initializers/logstasher.rb. Following are the code inside the file “logstasher.rb”

if LogStasher.enabled
 LogStasher.add_custom_fields do |fields|
    fields[:country_code] = "US"
 end
end

After that I have restarted the webrick server, but the LogStasher.enaabled returns nil value and not storing the country code in the log file.

My requirement is like, I need to save the location information to the log file with the other information to display the kibana map.

Can you plz help me?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

LogStasher.add_custom_fields do |fields|
  ip = request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip

  puts "-" * 10
  puts ip
  puts "-" * 10

  fields[:ipaddr] = ip
end

This produces the IP in the logs but no custom field.