Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Oct 11, 2024
1 parent 3a053a8 commit b5679df
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/main/java/it/gov/pagopa/payments/utils/SchedulerUtils.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package it.gov.pagopa.payments.utils;

import org.slf4j.MDC;
import static it.gov.pagopa.payments.config.LoggingAspect.*;

import java.util.Calendar;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;

import static it.gov.pagopa.payments.config.LoggingAspect.*;


@Slf4j
public class SchedulerUtils {

public static void updateMDCForStartExecution(String method, String args) {
MDC.put(METHOD, method);
MDC.put(START_TIME, String.valueOf(Calendar.getInstance().getTimeInMillis()));
MDC.put(REQUEST_ID, UUID.randomUUID().toString());
MDC.put(OPERATION_ID, UUID.randomUUID().toString());
MDC.put(ARGS, args);
}

public static void updateMDCForEndExecution() {
MDC.put(STATUS, "OK");
MDC.put(CODE, "201");
MDC.put(RESPONSE_TIME, getExecutionTime());
}

public static void updateMDCError(Exception e, String method) {
MDC.put(STATUS, "KO");
MDC.put(CODE, "500");
MDC.put(RESPONSE_TIME, getExecutionTime());
MDC.put(FAULT_CODE, method);
MDC.put(FAULT_DETAIL, e.getMessage());
}

public static void updateMDCForStartExecution(String method, String args) {
MDC.put(METHOD, method);
MDC.put(START_TIME, String.valueOf(Calendar.getInstance().getTimeInMillis()));
MDC.put(REQUEST_ID, UUID.randomUUID().toString());
MDC.put(OPERATION_ID, UUID.randomUUID().toString());
MDC.put(ARGS, args);
}

public static void updateMDCForEndExecution() {
MDC.put(STATUS, "OK");
MDC.put(CODE, "201");
MDC.put(RESPONSE_TIME, getExecutionTime());
log.info("Scheduled job finished successfully");
}

public static void updateMDCError(Exception e, String method) {
MDC.put(STATUS, "KO");
MDC.put(CODE, "500");
MDC.put(RESPONSE_TIME, getExecutionTime());
MDC.put(FAULT_CODE, method);
MDC.put(FAULT_DETAIL, e.getMessage());
log.info("An error occurring during a scheduled job");
}
}

0 comments on commit b5679df

Please sign in to comment.