From 81dc85c061ecd913c4f688defc9d97806b90ad26 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Fri, 5 Jun 2015 22:07:46 -0700 Subject: [PATCH] log to STDOUT by default --- .env.default | 2 ++ app/controllers/notices_controller.rb | 3 ++- app/models/backtrace.rb | 5 ++--- config/application.rb | 3 --- config/environment.rb | 11 +++++++++++ config/initializers/mongo.rb | 0 config/load.rb | 4 ++++ config/mongo.rb | 2 ++ 8 files changed, 23 insertions(+), 7 deletions(-) delete mode 100644 config/initializers/mongo.rb diff --git a/.env.default b/.env.default index b63b762..178d672 100644 --- a/.env.default +++ b/.env.default @@ -15,6 +15,8 @@ ERRBIT_PER_APP_EMAIL_AT_NOTICES=false ERRBIT_NOTIFY_AT_NOTICES='[0]' ERRBIT_PER_APP_NOTIFY_AT_NOTICES=false MONGO_URL='mongodb://localhost' +ERRBIT_LOG_LEVEL=info +ERRBIT_LOG_LOCATION=STDOUT GITHUB_URL='https://github.com' GITHUB_AUTHENTICATION=true GITHUB_ACCESS_SCOPE='[repo]' diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb index 6cb9076..6e1494c 100644 --- a/app/controllers/notices_controller.rb +++ b/app/controllers/notices_controller.rb @@ -2,7 +2,8 @@ class NoticesController < ApplicationController class ParamsError < StandardError; end - skip_before_action :authenticate_user!, :only => :create + skip_before_action :authenticate_user!, only: :create + skip_before_filter :verify_authenticity_token, only: :create rescue_from ParamsError, :with => :bad_params diff --git a/app/models/backtrace.rb b/app/models/backtrace.rb index bdebee7..86f0453 100644 --- a/app/models/backtrace.rb +++ b/app/models/backtrace.rb @@ -15,11 +15,11 @@ class Backtrace delegate :app, :to => :notice def self.find_or_create(attributes = {}) - new(attributes).similar || create(attributes) + new(attributes).similar.find_and_modify({ '$setOnInsert' => attributes }) end def similar - Backtrace.where(:fingerprint => fingerprint).first + Backtrace.where(:fingerprint => fingerprint) end def raw=(raw) @@ -32,5 +32,4 @@ class Backtrace def generate_fingerprint self.fingerprint = Digest::SHA1.hexdigest(lines.map(&:to_s).join) end - end diff --git a/config/application.rb b/config/application.rb index bd8f8d5..edb265a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,9 +19,6 @@ module Errbit config.autoload_paths += [Rails.root.join('lib')] config.before_initialize do - # Load up Errbit::Config with values from the environment - require Rails.root.join('config/load') - config.secret_key_base = Errbit::Config.secret_key_base config.serve_static_assets = Errbit::Config.serve_static_assets end diff --git a/config/environment.rb b/config/environment.rb index ee8d90d..2da595c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,16 @@ # Load the Rails application. require File.expand_path('../application', __FILE__) +# Load up Errbit::Config with values from the environment +require Rails.root.join('config/load') + +if Errbit::Config.log_location == 'STDOUT' + Rails.logger = ActiveSupport::Logger.new STDOUT +else + Rails.logger = ActiveSupport::Logger.new Errbit::Config.log_location +end + +Rails.logger.level = Errbit::Config.log_level.to_sym + # Initialize the Rails application. Rails.application.initialize! diff --git a/config/initializers/mongo.rb b/config/initializers/mongo.rb deleted file mode 100644 index e69de29..0000000 --- a/config/initializers/mongo.rb +++ /dev/null diff --git a/config/load.rb b/config/load.rb index c924cb9..b8bc4fe 100644 --- a/config/load.rb +++ b/config/load.rb @@ -1,6 +1,8 @@ # load default ENV values (without overwriting any existing value) Dotenv.load('.env.default') +require_relative '../lib/configurator' + # map config keys to environment variables # # We use the first non-nil environment variable in the list. If the last array @@ -19,6 +21,8 @@ Errbit::Config = Configurator.run({ per_app_email_at_notices: ['ERRBIT_PER_APP_EMAIL_AT_NOTICES'], notify_at_notices: ['ERRBIT_NOTIFY_AT_NOTICES'], per_app_notify_at_notices: ['ERRBIT_PER_APP_NOTIFY_AT_NOTICES'], + log_location: ['ERRBIT_LOG_LOCATION'], + log_level: ['ERRBIT_LOG_LEVEL'], serve_static_assets: ['SERVE_STATIC_ASSETS'], secret_key_base: ['SECRET_KEY_BASE'], diff --git a/config/mongo.rb b/config/mongo.rb index f9ad205..6ae18db 100644 --- a/config/mongo.rb +++ b/config/mongo.rb @@ -1,3 +1,5 @@ +Mongoid.logger.level = Logger.const_get Errbit::Config.log_level.upcase + Mongoid.configure do |config| uri = if Errbit::Config.mongo_url == 'mongodb://localhost' "mongodb://localhost/errbit_#{Rails.env}" -- libgit2 0.21.2