Skip to content

Commit

Permalink
Added logstasher for better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jamo committed Mar 4, 2016
1 parent 7ca34b9 commit a6065ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem "paperclip", "~> 4.3"
gem 'dalli'
gem 'gravtastic', '~> 3.2.6'

gem 'logstasher', '~> 0.9.0'

gem 'pghero'

Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 15 additions & 0 deletions config/initializers/logstasher.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a6065ee

Please sign in to comment.