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 committed Dec 6, 2023
1 parent 6a2e498 commit b1159a0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/initializers/logstasher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if Object.const_defined?("LogStasher") && LogStasher.enabled
LogStasher.add_custom_fields do |fields|
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 b1159a0

Please sign in to comment.