Skip to content

Commit

Permalink
Remove newline character from log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanKarab committed Oct 14, 2024
1 parent 4ff362a commit 002f1ff
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
28 changes: 14 additions & 14 deletions src/main/java/hbp/mip/experiment/ExperimentAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public ResponseEntity<ExperimentsDTO> getExperiments(Authentication authenticati
var logger = new Logger(activeUserService.getActiveUser(authentication).username(), "(GET) /experiments");
logger.info(
"Request for experiments with parameters: " +
"\n\tname -> " + name +
"\n\talgorithm -> " + algorithm +
"\n\tshared -> " + shared +
"\n\tviewed -> " + viewed +
"\n\tincludeShared -> " + includeShared +
"\n\torderBy -> " + orderBy +
"\n\tdescending -> " + descending +
"\n\tpage -> " + page +
"\n\tsize -> " + size
"name -> " + name +
" , algorithm -> " + algorithm +
" , shared -> " + shared +
" , viewed -> " + viewed +
" , includeShared -> " + includeShared +
" , orderBy -> " + orderBy +
" , descending -> " + descending +
" , page -> " + page +
" , size -> " + size
);
var experimentsDTO = experimentService.getExperiments(authentication,
name,
Expand All @@ -71,7 +71,7 @@ public ResponseEntity<ExperimentsDTO> getExperiments(Authentication authenticati

@GetMapping(value = "/{uuid}")
public ResponseEntity<ExperimentDTO> getExperiment(Authentication authentication, @PathVariable("uuid") String uuid) {
var logger = new Logger(activeUserService.getActiveUser(authentication).username(), "(GET) /experiments/{uuid}");
var logger = new Logger(activeUserService.getActiveUser(authentication).username(), "(GET) /experiments/" + uuid);
logger.info("Request for experiment with id: " + uuid);
var experimentResponse = experimentService.getExperiment(authentication, uuid, logger);
logger.info("Experiment returned.");
Expand All @@ -92,7 +92,7 @@ public ResponseEntity<ExperimentDTO> createExperiment(Authentication authenticat
@PatchMapping(value = "/{uuid}")
public ResponseEntity<ExperimentDTO> updateExperiment(Authentication authentication, @RequestBody ExperimentDTO experimentRequest, @PathVariable("uuid") String uuid) {
var user = activeUserService.getActiveUser(authentication);
var logger = new Logger(user.username(), "(PATCH) /experiments/{uuid}");
var logger = new Logger(user.username(), "(PATCH) /experiments/" + uuid);
logger.info("Request for experiment update with id: " + uuid + ". Request Body: " + JsonConverters.convertObjectToJsonString(experimentRequest));
var experimentResponse = experimentService.updateExperiment(user, uuid, experimentRequest, logger);
logger.info("Experiment updated. Id: " + uuid);
Expand All @@ -103,7 +103,7 @@ public ResponseEntity<ExperimentDTO> updateExperiment(Authentication authenticat
@RequestMapping(value = "/{uuid}", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteExperiment(Authentication authentication, @PathVariable("uuid") String uuid) {
var user = activeUserService.getActiveUser(authentication);
var logger = new Logger(user.username(), "(DELETE) /experiments/{uuid}");
var logger = new Logger(user.username(), "(DELETE) /experiments/" + uuid);
logger.info("Request for experiment deletion with id: " + uuid);
experimentService.deleteExperiment(user, uuid, logger);
logger.info("Experiment deleted. Id: " + uuid);
Expand All @@ -124,8 +124,8 @@ public ResponseEntity<ExperimentDTO> createTransientExperiment(Authentication au

logger.info(
"Experiment (transient) finished. " +
"\n\tStatus: " + experimentResponse.status() +
"\n\tResult: " + experimentResponse.result()
" Status: " + experimentResponse.status() +
" Result: " + experimentResponse.result()
);

return new ResponseEntity<>(experimentResponse, HttpStatus.OK);
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/hbp/mip/experiment/ExperimentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public ExperimentDTO createExperiment(Authentication authentication, ExperimentE
experimentDAO.setStatus((exaremeExperimentAlgorithmResultDTO.code() >= 400)
? ExperimentDAO.Status.error : ExperimentDAO.Status.success);
} catch (Exception e) {
logger.error("Exareme2 algorithm execution failed: " + e.getMessage() + "\nStacktrace: " + Arrays.toString(e.getStackTrace()));
logger.error("Exareme2 algorithm execution failed: " + e.getMessage() + " Stacktrace: " + Arrays.toString(e.getStackTrace()));
experimentDAO.setStatus(ExperimentDAO.Status.error);
}

Expand Down Expand Up @@ -289,36 +289,33 @@ private void algorithmParametersLogging(ExperimentExecutionDTO experimentExecuti
if (algorithm.parameters() != null) {
algorithm.parameters().forEach(
params -> parametersLogMessage
.append(" ")
.append(" ")
.append(params.name())
.append(" -> ")
.append(params.value())
.append("\n"));
);
}

if (algorithm.preprocessing() != null) {
algorithm.preprocessing().forEach(transformer ->
{
parametersLogMessage
.append(" ")
.append(" ")
.append(transformer.name())
.append(" -> ")
.append("\n");
.append(" -> ");

if (transformer.parameters() != null) {
transformer.parameters().forEach(
transformerParams -> parametersLogMessage
.append(" ")
.append(" ")
.append(transformerParams.name())
.append(" -> ")
.append(transformerParams.value())
.append("\n"));
parametersLogMessage.append("\n");
.append(transformerParams.value()));
}
});
}

logger.debug("Algorithm " + algorithmName + " execution starting with parameters: \n" + parametersLogMessage);
logger.debug("Algorithm " + algorithmName + " execution starting with parameters: " + parametersLogMessage);
}

private String getExperimentDatasets(ExperimentExecutionDTO experimentExecutionDTO, Logger logger) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hbp/mip/utils/ControllerExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public ResponseEntity<ErrorMessage> handleNoContent(NoContent nc, WebRequest req
@ExceptionHandler({InternalServerError.class, Exception.class})
public ResponseEntity<ErrorMessage> globalExceptionHandler(Exception ex, WebRequest request) {
logger.error("An unexpected exception occurred: " + ex.getClass() +
"\nMessage: " + ex.getMessage() +
"\nStacktrace: " + Arrays.toString(ex.getStackTrace()).replaceAll(", ", "\n")
" Message: " + ex.getMessage() +
" Stacktrace: " + Arrays.toString(ex.getStackTrace())
);
ErrorMessage message = new ErrorMessage(
HttpStatus.INTERNAL_SERVER_ERROR.value(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hbp/mip/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Logger(String username, String endpoint) {
}

private void logUserAction(String message, String logLevel){
String logMessage = " User -> " + username + " , " + "Endpoint -> " + endpoint + " , " + "Info -> " + message;
String logMessage = "User -> " + username + " , Endpoint -> " + endpoint + " , Info -> " + message;

switch (logLevel) {
case "ERROR" -> logger.error(logMessage);
Expand Down

0 comments on commit 002f1ff

Please sign in to comment.