-
-
Save McGeekiest/13446c49c70eb73e31b1 to your computer and use it in GitHub Desktop.
Customizing Lograge: Removing and adding fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/application_controller.rb | |
# class ApplicationController < ActionController::Base | |
require "browser" | |
def append_info_to_payload(payload) | |
super | |
payload[:user_agent] = browser.user_agent | |
payload[:search_engine] = browser.search_engine? | |
end | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/utils/custom_formatter.rb | |
module Lograge | |
module Formatters | |
class CustomFormatter < Lograge::Formatters::KeyValue | |
def call(data) | |
data = data.delete_if do |k| | |
[:controller, :action, :format].include? k | |
end | |
super | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
# add at the end, then run `bundle install` | |
gem 'lograge' | |
gem 'browser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/lograge.rb | |
# Replace 'YourApp' with the name of your app | |
YourApp::Application.configure do | |
require File.expand_path(Rails.root.join('lib', 'utils', 'custom_formatter.rb'), __FILE__) | |
config.lograge.enabled = true | |
config.lograge.formatter = Lograge::Formatters::CustomFormatter.new | |
config.lograge.custom_options = lambda do |event| | |
{:time => event.time, :search_engine => event.payload[:search_engine], :user_agent => event.payload[:user_agent]} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment