Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug dhis2 18234 2.40.5 #18942

Open
wants to merge 3 commits into
base: patch/2.40.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions dhis-2/dhis-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</properties>

<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-api</artifactId>
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
2 changes: 1 addition & 1 deletion dhis-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<velocity-tools.version>2.0</velocity-tools.version>

<!-- Jackson -->
<jackson.version>2.14.3</jackson.version>
<jackson.version>2.18.0</jackson.version>
<jackson-datatype-jts.version>2.14</jackson-datatype-jts.version>
<geojson-jackson.version>1.14</geojson-jackson.version>

Expand Down
Loading