Skip to content

Commit

Permalink
CIRC-2111 Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkurash committed Jun 21, 2024
1 parent 007de1b commit 82a8de3
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.circulation.resources;

import static org.apache.logging.log4j.Level.DEBUG;
import static org.folio.circulation.infrastructure.storage.CirculationSettingsRepository.RECORDS_PROPERTY_NAME;
import static org.folio.circulation.support.ValidationErrorFailure.singleValidationError;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;
Expand All @@ -11,6 +12,7 @@
import java.util.UUID;
import java.util.function.Function;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.CirculationSetting;
Expand Down Expand Up @@ -75,10 +77,9 @@ void get(RoutingContext routingContext) {
final var clients = Clients.create(context, client);
final var circulationSettingsRepository = new CirculationSettingsRepository(clients);

log.debug("get:: parameters id: {}", routingContext.request().getParam("id"));

ofAsync(routingContext.request().getParam("id"))
.thenApply(refuseWhenIdIsInvalid())
.thenApply(r -> r.map(id -> logAndReturn(id, DEBUG, "get:: parameters id: {}", id)))
.thenCompose(r -> r.after(circulationSettingsRepository::getById))
.thenApply(r -> r.map(CirculationSetting::getRepresentation))
.thenApply(r -> r.map(JsonHttpResponse::ok))
Expand All @@ -90,10 +91,9 @@ void delete(RoutingContext routingContext) {
final var context = new WebContext(routingContext);
final var clients = Clients.create(context, client);

log.debug("get:: parameters id: {}", routingContext.request().getParam("id"));

ofAsync(routingContext.request().getParam("id"))
.thenApply(refuseWhenIdIsInvalid())
.thenApply(r -> r.map(id -> logAndReturn(id, DEBUG, "delete:: parameters id: {}", id)))
.thenCompose(r -> r.after(clients.circulationSettingsStorageClient()::delete))
.thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent)))
.thenAccept(context::writeResultToHttpResponse);
Expand All @@ -106,7 +106,7 @@ void getMany(RoutingContext routingContext) {
final var circulationSettingsRepository = new CirculationSettingsRepository(clients);

final var query = routingContext.request().query();
log.debug("get:: parameters id: {}", query);
log.debug("get:: parameters id: {}", () -> query);

circulationSettingsRepository.findBy(query)
.thenApply(multipleLoanRecordsResult -> multipleLoanRecordsResult.map(multipleRecords ->
Expand Down Expand Up @@ -153,4 +153,11 @@ private static boolean uuidIsValid(String providedId) {
return false;
}
}

private static <T> T logAndReturn(T returnValue, Level level, String message,
Object... params) {

log.log(level, message, params);
return returnValue;
}
}

0 comments on commit 82a8de3

Please sign in to comment.