diff --git a/Gemfile b/Gemfile index 45c93c98c..e89b6f3e8 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem "paperclip", "~> 4.3" gem 'dalli' gem 'gravtastic', '~> 3.2.6' +gem 'logstasher', '~> 0.9.0' gem 'pghero' diff --git a/Gemfile.lock b/Gemfile.lock index f71a8df22..384b215cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,12 @@ GEM logging (2.0.0) little-plugger (~> 1.1) multi_json (~> 1.10) + logstash-event (1.2.02) + logstasher (0.9.0) + activerecord (>= 3.0) + activesupport (>= 3.0) + logstash-event (~> 1.2.0) + request_store loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.3) @@ -237,6 +243,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.1.0) rake (10.5.0) + request_store (1.3.0) responders (2.1.1) railties (>= 4.2.0, < 5.1) rest-client (1.8.0) @@ -352,6 +359,7 @@ DEPENDENCIES gravtastic (~> 3.2.6) jquery-rails (~> 3.1.2) launchy + logstasher (~> 0.9.0) mimemagic (~> 0.3.0) mimic (~> 0.4.3) natcmp (~> 1.4) diff --git a/config/environments/development.rb b/config/environments/development.rb index ddf0e90cc..9f2bb636f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,6 @@ Rails.application.configure do + config.logstasher.enabled = true + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on diff --git a/config/environments/production.rb b/config/environments/production.rb index 0c95f1ab4..34c51b619 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,6 @@ Rails.application.configure do + config.logstasher.enabled = false + # # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. diff --git a/config/initializers/logstasher.rb b/config/initializers/logstasher.rb new file mode 100644 index 000000000..28345b8d6 --- /dev/null +++ b/config/initializers/logstasher.rb @@ -0,0 +1,15 @@ +if LogStasher.enabled? + LogStasher.add_custom_fields do |fields| + # This block is run in application_controller context, + # so you have access to all controller methods + if current_user + fields[:user] = current_user.login + else + fields[:user] = 'guest' + end + fields[:site] = request.path =~ /^\/api/ ? 'api' : 'user' + + # If you are using custom instrumentation, just add it to logstasher custom fields + LogStasher.custom_fields << :myapi_runtime + end +end