FIX: stop logging way too much information

This commit is contained in:
Sam 2014-08-05 16:14:10 +10:00
parent 40bcead099
commit 3cab3acd60
4 changed files with 31 additions and 11 deletions

View File

@ -157,7 +157,7 @@ GEM
thor (~> 0.15)
libv8 (3.16.14.3)
listen (0.7.3)
logster (0.1.2)
logster (0.1.3)
lru_redux (0.8.1)
mail (2.5.4)
mime-types (~> 1.16)

View File

@ -6,7 +6,7 @@ class TopicViewItem < ActiveRecord::Base
belongs_to :user
validates_presence_of :topic_id, :ip_address, :viewed_at
def self.add(topic_id, ip, user_id, at=nil)
def self.add(topic_id, ip, user_id=nil, at=nil, skip_redis=false)
# Only store a view once per day per thing per user per ip
redis_key = "view:#{topic_id}:#{Date.today.to_s}"
if user_id
@ -15,11 +15,13 @@ class TopicViewItem < ActiveRecord::Base
redis_key << ":ip-#{ip}"
end
if $redis.setnx(redis_key, "1")
$redis.expire(redis_key, 1.day.to_i)
if skip_redis || $redis.setnx(redis_key, "1")
skip_redis || $redis.expire(redis_key, 1.day.to_i)
TopicViewItem.transaction do
at ||= Date.today
# AR likes logging failures here, we don't need that
TopicViewItem.create!(topic_id: topic_id, ip_address: ip, viewed_at: at, user_id: user_id)
# Update the views count in the parent, if it exists.

View File

@ -1,10 +1,13 @@
if Rails.env.production?
# Logster.store.ignore = [
# # honestly, Rails should not be logging this, its real noisy
# /^ActionController::RoutingError \(No route matches/,
# # suppress trackback spam bots
# Logster::IgnorePattern.new("Can't verify CSRF token authenticity", { REQUEST_URI: /\/trackback\/$/ })
# ]
Logster.store.ignore = [
# honestly, Rails should not be logging this, its real noisy
/^ActionController::RoutingError \(No route matches/,
/^PG::Error: ERROR:\s+duplicate key/,
# suppress trackback spam bots
Logster::IgnorePattern.new("Can't verify CSRF token authenticity", { REQUEST_URI: /\/trackback\/$/ })
]
Logster.config.authorize_callback = lambda{|env|
user = CurrentUser.lookup_from_env(env)

View File

@ -1,5 +1,20 @@
require 'spec_helper'
describe TopicView do
describe TopicViewItem do
def add(topic_id, ip, user_id=nil)
skip_redis = true
TopicViewItem.add(topic_id, ip, user_id, nil, skip_redis)
end
it "raises nothing for dupes" do
add(2, "1.1.1.1")
add(2, "1.1.1.1", 1)
TopicViewItem.create!(topic_id: 1, ip_address: "1.1.1.1", viewed_at: 1.day.ago)
add(1, "1.1.1.1")
TopicViewItem.count.should == 3
end
end