Skip to content

Commit

Permalink
Fix logger custom field config
Browse files Browse the repository at this point in the history
It turns out that you can't call `LogStasher.add_custom_fields` twice.
Because Content Store's custom fields config was being run after the
govuk_app_config gem's own custom fields config, the gem's config was
being overwritten. So, fields like `govuk_request_id` and `varnish_id`
weren't appearing in Content Store's controller request logs (but
`govuk_dependency_resolution_source_content_id` was).

The gem (version 9.7.0) now provides a mechanism for setting custom
fields that doesn't overwrite the gem's own settings
https://docs.publishing.service.gov.uk/repos/govuk_app_config.html#logger-configuration:

```
GovukJsonLogging.configure do
  add_custom_fields do |fields|
    fields[:govuk_custom_field] = request.headers["GOVUK-Custom-Header"]
  end
end
```
  • Loading branch information
mike29736 authored and brucebolt committed Dec 27, 2023
1 parent a9b67dc commit 29b36f0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions config/initializers/logstasher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
unless Rails.env.test?
GovukJsonLogging.configure do
add_custom_fields do |fields|
fields[:govuk_dependency_resolution_source_content_id] = request.headers["GOVUK-Dependency-Resolution-Source-Content-Id"]
end
GovukJsonLogging.configure do
add_custom_fields do |fields|
fields[:govuk_dependency_resolution_source_content_id] = request.headers["GOVUK-Dependency-Resolution-Source-Content-Id"]
end
end

0 comments on commit 29b36f0

Please sign in to comment.