Commit 81dc85c061ecd913c4f688defc9d97806b90ad26

Authored by Stephen Crosby
1 parent bdf4aa57
Exists in master and in 1 other branch production

log to STDOUT by default

inspired by 12-factor, we now log to STDOUT by default instead of a
named log file in ./log. This is just a default, and you can still
configure your own log location using ERRBIT_LOG_LOCATION.
@@ -15,6 +15,8 @@ ERRBIT_PER_APP_EMAIL_AT_NOTICES=false @@ -15,6 +15,8 @@ ERRBIT_PER_APP_EMAIL_AT_NOTICES=false
15 ERRBIT_NOTIFY_AT_NOTICES='[0]' 15 ERRBIT_NOTIFY_AT_NOTICES='[0]'
16 ERRBIT_PER_APP_NOTIFY_AT_NOTICES=false 16 ERRBIT_PER_APP_NOTIFY_AT_NOTICES=false
17 MONGO_URL='mongodb://localhost' 17 MONGO_URL='mongodb://localhost'
  18 +ERRBIT_LOG_LEVEL=info
  19 +ERRBIT_LOG_LOCATION=STDOUT
18 GITHUB_URL='https://github.com' 20 GITHUB_URL='https://github.com'
19 GITHUB_AUTHENTICATION=true 21 GITHUB_AUTHENTICATION=true
20 GITHUB_ACCESS_SCOPE='[repo]' 22 GITHUB_ACCESS_SCOPE='[repo]'
app/controllers/notices_controller.rb
@@ -2,7 +2,8 @@ class NoticesController < ApplicationController @@ -2,7 +2,8 @@ class NoticesController < ApplicationController
2 2
3 class ParamsError < StandardError; end 3 class ParamsError < StandardError; end
4 4
5 - skip_before_action :authenticate_user!, :only => :create 5 + skip_before_action :authenticate_user!, only: :create
  6 + skip_before_filter :verify_authenticity_token, only: :create
6 7
7 rescue_from ParamsError, :with => :bad_params 8 rescue_from ParamsError, :with => :bad_params
8 9
app/models/backtrace.rb
@@ -15,11 +15,11 @@ class Backtrace @@ -15,11 +15,11 @@ class Backtrace
15 delegate :app, :to => :notice 15 delegate :app, :to => :notice
16 16
17 def self.find_or_create(attributes = {}) 17 def self.find_or_create(attributes = {})
18 - new(attributes).similar || create(attributes) 18 + new(attributes).similar.find_and_modify({ '$setOnInsert' => attributes })
19 end 19 end
20 20
21 def similar 21 def similar
22 - Backtrace.where(:fingerprint => fingerprint).first 22 + Backtrace.where(:fingerprint => fingerprint)
23 end 23 end
24 24
25 def raw=(raw) 25 def raw=(raw)
@@ -32,5 +32,4 @@ class Backtrace @@ -32,5 +32,4 @@ class Backtrace
32 def generate_fingerprint 32 def generate_fingerprint
33 self.fingerprint = Digest::SHA1.hexdigest(lines.map(&:to_s).join) 33 self.fingerprint = Digest::SHA1.hexdigest(lines.map(&:to_s).join)
34 end 34 end
35 -  
36 end 35 end
config/application.rb
@@ -19,9 +19,6 @@ module Errbit @@ -19,9 +19,6 @@ module Errbit
19 config.autoload_paths += [Rails.root.join('lib')] 19 config.autoload_paths += [Rails.root.join('lib')]
20 20
21 config.before_initialize do 21 config.before_initialize do
22 - # Load up Errbit::Config with values from the environment  
23 - require Rails.root.join('config/load')  
24 -  
25 config.secret_key_base = Errbit::Config.secret_key_base 22 config.secret_key_base = Errbit::Config.secret_key_base
26 config.serve_static_assets = Errbit::Config.serve_static_assets 23 config.serve_static_assets = Errbit::Config.serve_static_assets
27 end 24 end
config/environment.rb
1 # Load the Rails application. 1 # Load the Rails application.
2 require File.expand_path('../application', __FILE__) 2 require File.expand_path('../application', __FILE__)
3 3
  4 +# Load up Errbit::Config with values from the environment
  5 +require Rails.root.join('config/load')
  6 +
  7 +if Errbit::Config.log_location == 'STDOUT'
  8 + Rails.logger = ActiveSupport::Logger.new STDOUT
  9 +else
  10 + Rails.logger = ActiveSupport::Logger.new Errbit::Config.log_location
  11 +end
  12 +
  13 +Rails.logger.level = Errbit::Config.log_level.to_sym
  14 +
4 # Initialize the Rails application. 15 # Initialize the Rails application.
5 Rails.application.initialize! 16 Rails.application.initialize!
config/initializers/mongo.rb
config/load.rb
1 # load default ENV values (without overwriting any existing value) 1 # load default ENV values (without overwriting any existing value)
2 Dotenv.load('.env.default') 2 Dotenv.load('.env.default')
3 3
  4 +require_relative '../lib/configurator'
  5 +
4 # map config keys to environment variables 6 # map config keys to environment variables
5 # 7 #
6 # We use the first non-nil environment variable in the list. If the last array 8 # We use the first non-nil environment variable in the list. If the last array
@@ -19,6 +21,8 @@ Errbit::Config = Configurator.run({ @@ -19,6 +21,8 @@ Errbit::Config = Configurator.run({
19 per_app_email_at_notices: ['ERRBIT_PER_APP_EMAIL_AT_NOTICES'], 21 per_app_email_at_notices: ['ERRBIT_PER_APP_EMAIL_AT_NOTICES'],
20 notify_at_notices: ['ERRBIT_NOTIFY_AT_NOTICES'], 22 notify_at_notices: ['ERRBIT_NOTIFY_AT_NOTICES'],
21 per_app_notify_at_notices: ['ERRBIT_PER_APP_NOTIFY_AT_NOTICES'], 23 per_app_notify_at_notices: ['ERRBIT_PER_APP_NOTIFY_AT_NOTICES'],
  24 + log_location: ['ERRBIT_LOG_LOCATION'],
  25 + log_level: ['ERRBIT_LOG_LEVEL'],
22 26
23 serve_static_assets: ['SERVE_STATIC_ASSETS'], 27 serve_static_assets: ['SERVE_STATIC_ASSETS'],
24 secret_key_base: ['SECRET_KEY_BASE'], 28 secret_key_base: ['SECRET_KEY_BASE'],
config/mongo.rb
  1 +Mongoid.logger.level = Logger.const_get Errbit::Config.log_level.upcase
  2 +
1 Mongoid.configure do |config| 3 Mongoid.configure do |config|
2 uri = if Errbit::Config.mongo_url == 'mongodb://localhost' 4 uri = if Errbit::Config.mongo_url == 'mongodb://localhost'
3 "mongodb://localhost/errbit_#{Rails.env}" 5 "mongodb://localhost/errbit_#{Rails.env}"