diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 7ded695c1d74cddda19158b43cf9cf6ef9bf3efd..ac406e7730cbc7ef9f37b97f1e3bd248043d674b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -21,8 +21,8 @@ class CommentsController < ApplicationController @comment = current_user.build_comment(:text => text, :post => target) if @comment.save - Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle, - :status => :success, :comment => @comment.id, :chars => params[:text].length) + Rails.logger.info("event => :create, :type => :comment, :user => #{current_user.diaspora_handle}, + :status => :success, :comment => #{@comment.id}, :chars => #{params[:text].length}") Postzord::Dispatcher.build(current_user, @comment).post respond_to do |format| diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 08c22913e6eef748435934bbd9dcee581b87265e..9a3210d49f25a0d59432239cfc5819089861211b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -40,7 +40,7 @@ class PostsController < ApplicationController else user_id = (user_signed_in? ? current_user : nil) - Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => user_id, :post_id => params[:id]) + Rails.logger.info(":event => :link_to_nonexistent_post, :ref => #{request.env['HTTP_REFERER']}, :user_id => #{user_id}, :post_id => #{params[:id]}") flash[:error] = I18n.t('posts.show.not_found') redirect_to :back end diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 5de95dd08104be34e7f7bb3a83220f1863fcdc59..142ace589106c5a52a243773529cc0e857f62921 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -57,7 +57,7 @@ module SocketsHelper raise "#{object.inspect} with class #{object.class} is not actionhashable." unless object.is_a? Retraction end rescue Exception => e - Rails.logger.error(:event => :socket_render, :status => :fail, :user => user.diaspora_handle, :object=> object.id, :object_class => object.class, :error_message => e.message) + Rails.logger.error(":event => :socket_render, :status => :fail, :user => #{user.diaspora_handle}, :object=> #{object.id}, :object_class => #{object.class}, :error_message => #{e.message}") raise e end action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)} diff --git a/app/models/signed_retraction.rb b/app/models/signed_retraction.rb index 3c23600111fc915a85bf1773a9dd76ce0406bdea..bde437471c5e966bbb656ed4cbb68311d0b4712d 100644 --- a/app/models/signed_retraction.rb +++ b/app/models/signed_retraction.rb @@ -82,7 +82,7 @@ class SignedRetraction self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user self.target.destroy end - Rails.logger.info(:event => :retraction, :status => :complete, :target_type => self.target_type, :guid => self.target_guid) + Rails.logger.info("event=retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}") end def receive(recipient, sender) diff --git a/chef/cookbooks/diaspora/recipes/backup.rb b/chef/cookbooks/diaspora/recipes/backup.rb index 39ac465f9f91ad392e3a67c61b5c2b04d1978139..f5b5d4a139037f05ed0976dac923c47057f7f394 100644 --- a/chef/cookbooks/diaspora/recipes/backup.rb +++ b/chef/cookbooks/diaspora/recipes/backup.rb @@ -4,12 +4,6 @@ cron "user stats" do command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace statistics:users_splunk &> /usr/local/app/diaspora/log/stats.log" end -cron "content stats" do - minute 42 - hour 15 - command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace statistics:content_splunk &> /usr/local/app/diaspora/log/stats.log" -end - cron "backup mysql" do minute 0 command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace backup:mysql" diff --git a/chef/cookbooks/diaspora/recipes/default.rb b/chef/cookbooks/diaspora/recipes/default.rb index b96e987f0d150f4cf6fc90c286f335c46b6c2bdc..66487de08dd605983b3fee56375bf26f5f660c37 100644 --- a/chef/cookbooks/diaspora/recipes/default.rb +++ b/chef/cookbooks/diaspora/recipes/default.rb @@ -2,7 +2,6 @@ include_recipe "diaspora::image_magick" include_recipe "diaspora::mysql" include_recipe "diaspora::iptables" include_recipe "diaspora::daemontools" -include_recipe "diaspora::splunk" include_recipe "diaspora::backup" include_recipe "diaspora::nginx" include_recipe "diaspora::redis" diff --git a/chef/cookbooks/diaspora/recipes/splunk.rb b/chef/cookbooks/diaspora/recipes/splunk.rb deleted file mode 100644 index 5142437e467bc4cd0b925dd089d6f07023cb0ad7..0000000000000000000000000000000000000000 --- a/chef/cookbooks/diaspora/recipes/splunk.rb +++ /dev/null @@ -1,44 +0,0 @@ -unless system "splunk status" - execute "Make Temp Dir" do - command "mkdir -p /tmp/install" - end - - execute "Download splunk" do - command "cd /tmp/install && wget 'http://www.splunk.com/index.php/download_track?file=4.1.5/linux/splunk-4.1.5-85165-Linux-x86_64.tgz&ac=&wget=true&name=wget&typed=releases' -O splunk-4.1.5-85165-Linux-x86_64.tgz" - end - - execute "Untar splunk" do - command "tar -xvf /tmp/install/splunk-4.1.5-85165-Linux-x86_64.tgz -C /opt/" - end - - link "/usr/local/bin/splunk" do - to "/opt/splunk/bin/splunk" - end -end - -execute "Start splunk" do - command "splunk start --accept-license || true" -end - -execute "Put splunk into forwarding mode" do - command "splunk enable app SplunkLightForwarder -auth admin:changeme" -end - -execute "Add forwarding server" do - command "splunk add forward-server splunk.joindiaspora.com:9997 -auth admin:changeme" - not_if "splunk list forward-server | grep splunk.joindiaspora.com:9997" -end - -execute "Add monitor for diaspora" do - command "splunk add monitor /usr/local/app/diaspora/log" - not_if "splunk list monitor | grep diaspora" -end - -execute "Add monitor for nginx" do - command "mkdir -p /usr/local/nginx/logs && splunk add monitor /usr/local/nginx/logs" - not_if "splunk list monitor | grep nginx" -end - -execute 'Splunk Restart' do - command "splunk restart" -end diff --git a/config/application.yml.example b/config/application.yml.example index d2e7bddc172b0646d86be1084ee315a11a00996d..0cd60599ec959d4beedcff3146201314d64d8d30 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -85,9 +85,6 @@ defaults: &defaults # Enable extensive logging to log/{development,test,production}.log debug: false - # If you want normal Rails logs, set this to false in the appropriate environment. - # It is false by default in development and test. - enable_splunk_logging: true # Enable extensive logging to websocket server. socket_debug : false @@ -215,7 +212,6 @@ defaults: &defaults development: <<: *defaults - enable_splunk_logging: false production: <<: *defaults @@ -228,15 +224,12 @@ test: <<: *defaults pod_url: "http://localhost:9887" socket_port: 8081 - enable_splunk_logging: false open_invitations: true integration_1: <<: *defaults pod_url: "http://localhost:45789" - enable_splunk_logging: false integration_2: <<: *defaults pod_url: "http://localhost:34658" - enable_splunk_logging: false diff --git a/config/initializers/_splunk_logger.rb b/config/initializers/_splunk_logger.rb deleted file mode 100644 index 5cb075836bfd266a2431e6385b4e460048fd7c93..0000000000000000000000000000000000000000 --- a/config/initializers/_splunk_logger.rb +++ /dev/null @@ -1,5 +0,0 @@ -if AppConfig[:enable_splunk_logging] - require File.expand_path('../../../lib/log_overrider', __FILE__) -end - -Rails.logger.class.send(:include, SplunkLogging) diff --git a/db/schema.rb b/db/schema.rb index d224545e85442dfbd9bfdb9542ec406686de34cc..ee8028fffbd653d81d8e6af72f3e56c79f8e2fe6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -314,8 +314,8 @@ ActiveRecord::Schema.define(:version => 20111217042006) do t.integer "likes_count", :default => 0 t.integer "comments_count", :default => 0 t.integer "o_embed_cache_id" - t.integer "reshares_count", :default => 0 t.integer "photos_count", :default => 0 + t.integer "reshares_count", :default => 0 end add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true diff --git a/lib/log_overrider.rb b/lib/log_overrider.rb deleted file mode 100644 index ff47558fad4b710552658d151eaf58d2655f2d48..0000000000000000000000000000000000000000 --- a/lib/log_overrider.rb +++ /dev/null @@ -1,88 +0,0 @@ -class ActionView::LogSubscriber - - # In order to be more friendly to Splunk, which we use for log analysis, - # we override a few logging methods. There are not overriden if enable_splunk_logging is set to false in config/application.yml - def render_template(event) - count = event.payload[:count] || 1 - hash = {:event => :render, - :template => from_rails_root(event.payload[:identifier]), - :total_ms => event.duration, - :count => count, - :ms => event.duration / count} - - hash.merge(:layout => event.payload[:layout]) if event.payload[:layout] - - Rails.logger.info(hash) - end - alias :render_partial :render_template - alias :render_collection :render_template -end - -module ActionDispatch - class ShowExceptions - private - # This override logs in a format Splunk can more easily understand. - # @see ActionView::LogSubscriber#render_template - def log_error(exception) - return unless logger - - ActiveSupport::Deprecation.silence do - message = "event=error error_class=#{exception.class} error_message='#{exception.message}' " - message << "gc_ms=#{GC.time/1000} gc_collections=#{GC.collections} gc_bytes=#{GC.growth} " if GC.respond_to?(:enable_stats) - message << "orig_error_message='#{exception.original_exception.message}'" if exception.respond_to?(:original_exception) - message << "annotated_source='#{exception.annoted_source_code.to_s}' " if exception.respond_to?(:annoted_source_code) - message << "app_backtrace='#{application_trace(exception).join(";")}'" - logger.fatal("\n\n#{message}\n\n") - end - end - end -end - -class ActionController::LogSubscriber - require "#{File.dirname(__FILE__)}/active_record_instantiation_logs.rb" - include Oink::InstanceTypeCounter - def start_processing(event) - #noop - end - - # This override logs in a format Splunk can more easily understand. - # @see ActionView::LogSubscriber#render_template - def process_action(event) - payload = event.payload - additions = ActionController::Base.log_process_action(payload) - params = payload[:params].except(*INTERNAL_PARAMS) - - log_hash = {:event => :request_completed, - :status => payload[:status], - :controller => payload[:controller], - :action => payload[:action], - :format => payload[:formats].first.to_s.upcase, - :ms => ("%.0f" % event.duration).to_i, - :params => params.inspect} - log_hash.merge!({ - :gc_ms => GC.time/1000, - :gc_collections => GC.collections, - :gc_bytes=> GC.growth}) if GC.respond_to?(:enable_stats) - - log_hash.merge!({:view_ms => payload[:view_runtime], - :db_ms => payload[:db_runtime]}) unless additions.blank? - log_hash.merge!(report_hash!) - - Rails.logger.info(log_hash) - end -end - -module Rails - module Rack - class Logger - # This override logs in a format Splunk can more easily understand. - # @see ActionView::LogSubscriber#render_template - def before_dispatch(env) - request = ActionDispatch::Request.new(env) - path = request.fullpath - - Rails.logger.info("event=request_started verb=#{env["REQUEST_METHOD"]} path=#{path} ip=#{request.ip} ") - end - end - end -end diff --git a/lib/salmon/encrypted_slap.rb b/lib/salmon/encrypted_slap.rb index 2770f1ad0af42ae6078dd96802fb004568255fbf..21cc7409cc054fd932e25fcc73a7e82c955b11d7 100644 --- a/lib/salmon/encrypted_slap.rb +++ b/lib/salmon/encrypted_slap.rb @@ -30,7 +30,7 @@ HEADER begin super rescue OpenSSL::PKey::RSAError => e - Rails.logger.info(:event => :invalid_rsa_key, :identifier => person.diaspora_handle) + Rails.logger.info("event => :invalid_rsa_key, :identifier => #{person.diaspora_handle}") false end end diff --git a/lib/splunk_logging.rb b/lib/splunk_logging.rb deleted file mode 100644 index 5c654aa5e1d1485b8218c48f86febd9caba7fff2..0000000000000000000000000000000000000000 --- a/lib/splunk_logging.rb +++ /dev/null @@ -1,32 +0,0 @@ -module SplunkLogging - def self.included(base) - base.class_eval do - alias_method_chain :add, :splunk - end - end - def add_with_splunk(arg1, log_hash = nil, arg3 = nil, &block) - if log_hash - string = format_hash(log_hash).dup - string << " pid=#{Process.pid} " - string << " time=#{Time.now.to_i} " - else - string = log_hash - end - add_without_splunk(arg1, string, arg3, &block) - end - def format_hash(hash) - if hash.respond_to?(:keys) - string = '' - hash.each_pair do |key, value| - if [Symbol, Fixnum, Float, Class].include?(value.class) - string << "#{key}=#{value} " - else - string << "#{key}=\"#{value.to_s.gsub('"', '\"')}\" " - end - end - string - else - hash - end - end -end diff --git a/lib/webfinger_profile.rb b/lib/webfinger_profile.rb index 7b7a08fa9808ca94c53e518653b7c452523db80b..51e54f18f4c1c257be0d9e06a5d73ef83083695e 100644 --- a/lib/webfinger_profile.rb +++ b/lib/webfinger_profile.rb @@ -41,7 +41,7 @@ class WebfingerProfile pubkey = text_of_attribute( doc.at('Link[rel=diaspora-public-key]'), 'href') @public_key = Base64.decode64 pubkey rescue Exception => e - Rails.logger.info(:event => :invalid_profile, :identifier => @account) + Rails.logger.info("event => :invalid_profile, :identifier => #{@account}") end end end diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index c8258f05c8a733311180456712e92658beb7a63f..6f65ee9a5ce215102ba193b3695926e9c3e5498b 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -3,7 +3,6 @@ # the COPYRIGHT file. require 'spec_helper' -require File.join(Rails.root, "spec", "shared_behaviors", "log_override") describe AspectsController do before do @@ -17,35 +16,6 @@ describe AspectsController do request.env["HTTP_REFERER"] = 'http://' + request.host end - describe "custom logging on success" do - before do - @action = :index - end - it_should_behave_like "it overrides the logs on success" - end - - describe "custom logging on error" do - class FakeError < RuntimeError; - attr_accessor :original_exception; - end - before do - @action = :index - @desired_error_message = "I love errors" - @error = FakeError.new(@desired_error_message) - @orig_error_message = "I loooooove nested errors!" - @error.original_exception = NoMethodError.new(@orig_error_message) - @controller.stub(:index).and_raise(@error) - end - it_should_behave_like "it overrides the logs on error" - end - - describe "custom logging on redirect" do - before do - @action = :show - @action_params = {'id' => @alices_aspect_1.id.to_s} - end - it_should_behave_like "it overrides the logs on redirect" - end describe "#new" do it "renders a remote form if remote is true" do diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 789f5720599fdd55f177898ab1576baf86ed0c06..0ef0f07aab2a9acea4036a5f6ee60117bd46bd5e 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -3,7 +3,6 @@ # the COPYRIGHT file. require 'spec_helper' -require File.join(Rails.root, "spec", "shared_behaviors", "log_override") describe HomeController do describe '#show' do @@ -17,24 +16,5 @@ describe HomeController do get :show, :home => true response.should redirect_to(multi_path) end - - describe "custom logging on success" do - before do - @action = :show - @action_params = {"lasers" => "green"} - end - - it_should_behave_like "it overrides the logs on success" - end - - describe "custom logging on redirect" do - before do - sign_in :user, bob - @action = :show - @action_params = {"lasers" => "green"} - end - - it_should_behave_like "it overrides the logs on redirect" - end end end diff --git a/spec/lib/diaspora/ostatus_builder_spec.rb b/spec/lib/diaspora/ostatus_builder_spec.rb index df990f8b5217d59523a2a7bfa66ad644d289bf95..f69d5800d0aafd3a583a9f83a01aa354af691540 100644 --- a/spec/lib/diaspora/ostatus_builder_spec.rb +++ b/spec/lib/diaspora/ostatus_builder_spec.rb @@ -37,7 +37,6 @@ describe Diaspora::OstatusBuilder do messages.each{ |message| atom2.should include message } end - include Oink::InstanceTypeCounter it 'does not query the db for the author of every post' do alice.person #Preload user.person ActiveRecord::Base.reset_instance_type_count diff --git a/spec/lib/resque_job_logging_spec.rb b/spec/lib/resque_job_logging_spec.rb index 835eef4845d6e7d382cd53b42028068523892d50..53a8999f983513ae8f91ae17364f55689db604b9 100644 --- a/spec/lib/resque_job_logging_spec.rb +++ b/spec/lib/resque_job_logging_spec.rb @@ -17,19 +17,6 @@ describe ResqueJobLogging do Rails.unstub!(:logger) end - # http://bugs.joindiaspora.com/issues/741 - it "should enumerate arguments" do - Rails.logger.should_receive(:info).with(/arg1="foo" arg2="bar" arg3="baz"/) - ## pass a nil block, so we can test the .info() output - ResqueJobLoggingDummy.around_perform_log_job("foo", "bar", "baz") {} - end - it 'logs stack traces on failure' do - Rails.logger.should_receive(:info).with(/app_backtrace=/) - error = RuntimeError.new("GRAAAAAAAAAGH") - proc { - ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error} - }.should raise_error(Regexp.new(error.message)) - end it 'notifies hoptoad if the hoptoad api key is set' do Rails.logger.should_receive(:info) diff --git a/spec/lib/splunk_logging_spec.rb b/spec/lib/splunk_logging_spec.rb deleted file mode 100644 index 1b7de5a30e861f385fccd23d95467e6050b30bd6..0000000000000000000000000000000000000000 --- a/spec/lib/splunk_logging_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' -describe SplunkLogging do - def add - - end - include SplunkLogging - describe '#format_hash' do - it 'does not quote keys' do - format_hash({:key => 'value'}).should =~ /key=/ - end - it 'quotes strings' do - format_hash({:key => 'value'}).should =~ /="value"/ - end - it 'does not quote symbols' do - format_hash({:key => :value}).should =~ /=value/ - end - it 'does not quote numbers' do - format_hash({:key => 500 }).should =~ /=500/ - end - it 'does not quote floats' do - format_hash({:key => 2.324}).should =~ /=2.324/ - end - it 'does not quote classes' do - format_hash({:key => Class}).should =~ /=Class/ - end - it 'escapes double quotes in strings' do - format_hash({:key => 'whaaa " quotes'}).should =~ /="whaaa \\\" quotes"/ - end - end -end diff --git a/spec/shared_behaviors/log_override.rb b/spec/shared_behaviors/log_override.rb deleted file mode 100644 index bd8c1d7448904debfb3b9430340af6d5cfdd88ce..0000000000000000000000000000000000000000 --- a/spec/shared_behaviors/log_override.rb +++ /dev/null @@ -1,99 +0,0 @@ -require File.expand_path('../../../lib/log_overrider', __FILE__) - -class FakeLogger - attr_accessor :infos - attr_accessor :lines - attr_accessor :fatals - - def initialize - self.infos = [] - self.fatals = [] - self.lines = [] - end - - def add(arg1, line, targ_arr, &block) - self.lines << line - targ_arr << line - end - def info line - self.add(nil, line, self.infos) - end - def fatal line - self.add(nil, line, self.fatals) - end - - include SplunkLogging -end - -shared_examples_for 'it overrides the logs on success' do - before do - Rails.stub(:logger).and_return(FakeLogger.new) - end - context 'rendering' do - it 'logs renders' do - get @action, @action_params - @lines = Rails.logger.infos.select { |l| l.include?("event=render") } - @lines.length.should > 0 - end - end - context 'completion' do - context 'ok' do - before do - get @action, @action_params - @line = Rails.logger.infos.last - end - it 'logs the completion of a request' do - @line.include?("event=request_completed").should be_true - end - it 'logs an ok' do - @line.include?("status=200").should be_true - end - it 'logs the controller' do - @line.include?("controller=\"#{controller.class.name}\"").should be_true - end - it 'logs the action' do - @line.include?("action=\"#{@action}\"").should be_true - end - it 'logs params' do - if @action_params - @line.include?("params=\"#{@action_params.inspect.gsub(" ", "").gsub("\"", "\\\"")}\"").should be_true - end - end - it 'logs the view rendering time addition' do - @line.include?("view_ms=").should be_true - end - end - end -end - -shared_examples_for 'it overrides the logs on error' do - before do - Rails.stub(:logger).and_return(FakeLogger.new) - begin - get @action, @action_params - rescue Exception => e - ActionDispatch::ShowExceptions.new(nil).send(:log_error,e) - end - @line = Rails.logger.lines.last - end - it 'logs the backtrace' do - @line.should =~ /app_backtrace=/ - end - it 'logs the error message' do - @line.should =~ /error_message='#{@desired_error_message}'/ - end - it 'logs the original error message, if it exists' do - @line.should =~ /orig_error_message='#{@orig_error_message}'/ if @orig_error_message - end -end - -shared_examples_for 'it overrides the logs on redirect' do - before do - Rails.stub(:logger).and_return(FakeLogger.new) - get @action, @action_params - @line = Rails.logger.infos.last - end - it 'logs a redirect' do - @line.include?("status=302").should be_true - end -end