Skip to content

Instantly share code, notes, and snippets.

@McGeekiest
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McGeekiest/13446c49c70eb73e31b1 to your computer and use it in GitHub Desktop.
Save McGeekiest/13446c49c70eb73e31b1 to your computer and use it in GitHub Desktop.
Customizing Lograge: Removing and adding fields
# 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
# 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
# Gemfile
# add at the end, then run `bundle install`
gem 'lograge'
gem 'browser'
# 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