generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a053a8
commit b5679df
Showing
1 changed file
with
27 additions
and
26 deletions.
There are no files selected for viewing
53 changes: 27 additions & 26 deletions
53
src/main/java/it/gov/pagopa/payments/utils/SchedulerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |