Skip to content

Commit

Permalink
Merge pull request #57 from companieshouse/KafkaMessageFormatsupport
Browse files Browse the repository at this point in the history
Adding jsonNode to format logs in json string
  • Loading branch information
dgurjar-ch authored Dec 20, 2024
2 parents 48d73dc + b9f210e commit 4ca1a61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>companies-house-parent</artifactId>
<version>2.1.10</version>
<version>2.1.11</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -98,6 +98,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring-boot-dependencies.version} </version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -123,24 +126,33 @@ private Map<String, Object> setCompletedDebugMap(DocumentGenerationCompleted com
Map<String, Object> completedParams = new HashMap<>();
completedParams.put(DESCRIPTION_IDENTIFIER, completed.getDescriptionIdentifier());
completedParams.put(DESCRIPTION, completed.getDescription());
completedParams.put(COMPLETED_DOCUMENT, completed);
completedParams.put(COMPLETED_DOCUMENT, getLogStatusTree(String.valueOf(completed)));

return completedParams;
}

private Map<String, Object> setFailedDebugMap(DocumentGenerationFailed failed) {

Map<String, Object> failedParams = new HashMap<>();
failedParams.put(FAILED_DOCUMENT, failed);
failedParams.put(FAILED_DOCUMENT, getLogStatusTree(String.valueOf(failed)));

return failedParams;
}

private Map<String, Object> setStartedDebugMap(DocumentGenerationStarted started) {

private Map<String, Object> setStartedDebugMap(DocumentGenerationStarted started) {
Map<String, Object> startedParams = new HashMap<>();
startedParams.put(STARTED_DOCUMENT, started);
startedParams.put(STARTED_DOCUMENT, getLogStatusTree(String.valueOf(started)));

return startedParams;
}

private JsonNode getLogStatusTree(String logStatus) {
try {
var mapper = new ObjectMapper();
return mapper.readTree(logStatus);
} catch (JsonProcessingException jsonProcessingException) {
LOG.error(" Found issue while converting into json String " + jsonProcessingException.getMessage());
return null;
}
}
}

0 comments on commit 4ca1a61

Please sign in to comment.