Skip to content

Commit

Permalink
Merge pull request #351 from alphagov/standardised-json-logging-for-g…
Browse files Browse the repository at this point in the history
…ovuk

Enabling Logstasher in production
  • Loading branch information
alext committed Dec 19, 2013
2 parents e696b4d + 765ca49 commit 3adde8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@
config.active_support.deprecation = :notify

config.action_controller.asset_host = ENV['GOVUK_ASSET_HOST']

# Enable JSON-style logging
config.logstasher.enabled = true
config.logstasher.logger = Logger.new("#{Rails.root}/log/#{Rails.env}.json.log")
config.logstasher.supress_app_log = true
end
8 changes: 8 additions & 0 deletions config/initializers/logstasher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if Object.const_defined?('LogStasher') && LogStasher.enabled
LogStasher.add_custom_fields do |fields|
# Mirrors Nginx request logging, e.g GET /path/here HTTP/1.1
fields[:request] = "#{request.request_method} #{request.fullpath} #{request.headers['SERVER_PROTOCOL']}"
# Pass X-Varnish to logging
fields[:varnish_id] = request.headers['X-Varnish']
end
end

0 comments on commit 3adde8b

Please sign in to comment.