Skip to content

Commit

Permalink
Debug PR for DHIS2-18234
Browse files Browse the repository at this point in the history
  • Loading branch information
netroms committed Oct 25, 2024
1 parent b5923db commit 46774bd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class Log4JLogConfigInitializer implements LogConfigInitializer {

private static final String LOG_DIR = "logs";

private static final String DATA_VALUE_INPUT = "dhis-datavalue-input.log";

private static final String ANALYTICS_TABLE_LOGGER_FILENAME = "dhis-analytics-table.log";

private static final String DATA_EXCHANGE_LOGGER_FILENAME = "dhis-data-exchange.log";
Expand Down Expand Up @@ -127,6 +129,9 @@ public void initConfig() {

locationManager.buildDirectory(LOG_DIR);

addConfigurableLogger(
DATA_VALUE_INPUT, Lists.newArrayList("org.hisp.dhis.webapi.controller.datavalue.input"));

addConfigurableLogger(
ANALYTICS_TABLE_LOGGER_FILENAME,
Lists.newArrayList("org.hisp.dhis.resourcetable", "org.hisp.dhis.analytics.table"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.category.CategoryOptionCombo;
Expand Down Expand Up @@ -100,6 +103,7 @@
*/
@OpenApi.Tags("data")
@RestController
@Slf4j
@RequestMapping(value = DataValueController.RESOURCE_PATH)
@ApiVersion({DhisApiVersion.DEFAULT, DhisApiVersion.ALL})
@RequiredArgsConstructor
Expand All @@ -126,6 +130,10 @@ public class DataValueController {

private final DhisConfigurationProvider dhisConfig;

// Custom logger for logging input payloads
private static final Logger inputLogger =
LogManager.getLogger("org.hisp.dhis.webapi.controller.datavalue.input");

// ---------------------------------------------------------------------
// POST
// ---------------------------------------------------------------------
Expand All @@ -148,22 +156,64 @@ public void saveDataValue(
@RequestParam(required = false) boolean force,
@CurrentUser User currentUser)
throws WebMessageException {
DataValueCategoryDto attribute = dataValidator.getDataValueCategoryDto(cc, cp);

DataValueDto dataValue =
new DataValueDto()
.setDataElement(de)
.setCategoryOptionCombo(co)
.setAttribute(attribute)
.setPeriod(pe)
.setOrgUnit(ou)
.setDataSet(ds)
.setValue(value)
.setComment(comment)
.setFollowUp(followUp)
.setForce(force);
// Log the input payload using the custom logger
inputLogger.info(
"Received payload: username={}, de={}, co={}, cc={}, cp={}, pe={}, ou={}, ds={}, value={}, comment={}, followUp={}, force={}",
currentUser.getUsername(),
de,
co,
cc,
cp,
pe,
ou,
ds,
value,
comment,
followUp,
force);

saveDataValueInternal(dataValue, currentUser);
try {
DataValueCategoryDto attribute = dataValidator.getDataValueCategoryDto(cc, cp);

DataValueDto dataValue =
new DataValueDto()
.setDataElement(de)
.setCategoryOptionCombo(co)
.setAttribute(attribute)
.setPeriod(pe)
.setOrgUnit(ou)
.setDataSet(ds)
.setValue(value)
.setComment(comment)
.setFollowUp(followUp)
.setForce(force);

saveDataValueInternal(dataValue, currentUser);
} catch (Exception e) {
log.error(
"Failed to save data value, LOGGING DATAVALUE EXCEPTION AND INPUT VALUES, Exception:"
+ e.getMessage(),
e);

// Log the input payload using the custom logger
log.error(
"Payload accompanying previous thrown exception: username={}, de={}, co={}, cc={}, cp={}, pe={}, ou={}, ds={}, value={}, comment={}, followUp={}, force={}",
currentUser.getUsername(),
de,
co,
cc,
cp,
pe,
ou,
ds,
value,
comment,
followUp,
force);

throw e;
}
}

@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
Expand Down

0 comments on commit 46774bd

Please sign in to comment.