Back-end Engineering Articles
I write and talk about backend stuff like Ruby, Ruby On Rails, Databases, Testing, Architecture / Infrastructure / System Design, Cloud, DevOps, Backgroud Jobs, and more...
2020-03-06
gem 'lograge' # bundle install
# /config/initializers/lograge.rb Rails.application.configure do config.lograge.enabled = true config.lograge.base_controller_class = 'ActionController::API' config.lograge.custom_options = lambda do |event| event.payload # Following this tutorial: <https://dev.to/mikerogers0/lorgage-taming-rails-logs-video-25il> # Rails.logger.debug(event.payload.inspect) # exceptions = [:controller, :action] # { # params: event.payload[:params].except(*exceptions) # # exception: event.payload[:exception], # ["ExceptionClass", "the message"] # # exception_object: event.payload[:exception_object] # the exception instance # } end end
# app/controllers/application_controller.rb def append_info_to_payload(payload) super payload[:user_id] = current_user_parso.try(:id) payload[:host] = request.host payload[:source_ip] = request.remote_ip end
method=GET path=/ format=html controller=Rails::WelcomeController action=index status=200 duration=127.37 view=71.80 db=0.00 params={"controller"=>"rails/welcome", "action"=>"index"} headers=#<ActionDispatch::Http::Headers:0x00000000048ddae8> view_runtime=71.80 db_runtime=0
gem 'remote_syslog_logger' # bundle install
# config/environments/development.rb config.logger = RemoteSyslogLogger.new('logs6.papertrailapp.com', 36377, program: "rails-development") # config/environments/production.rb config.logger = RemoteSyslogLogger.new('logs6.papertrailapp.com', 36377, program: "rails-production") # config/environments/staging.rb config.logger = RemoteSyslogLogger.new('logs6.papertrailapp.com', 36377, program: "rails-staging") # config/environments/test.rb config.logger = RemoteSyslogLogger.new('logs6.papertrailapp.com', 36377, program: "rails-test")