Skip to content

Instantly share code, notes, and snippets.

View tomajask's full-sized avatar
🚀

Thomas Jaskiewicz tomajask

🚀
View GitHub Profile
@tomajask
tomajask / remote_ip.rb
Last active March 10, 2017 11:31
Add 'remote_ip' to lograge logs
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def append_info_to_payload(payload)
super
payload[:remote_ip] = request.remote_ip
end
end
# config/environments/<your env>.rb
Rails.application.configure do
fields = %w(foo bar baz)
fields.each_with_object({}) do |field, memo|
memo[field] = rand(1000)
end
float = 123.45678
"%.4f" % float
# => "123.4568"
# or you can write it in a little bit different way
sprintf "%.4f", float
# => "123.4568"