diff --git a/openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/LogApi.java b/openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/LogApi.java deleted file mode 100644 index a700df3990..0000000000 --- a/openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/LogApi.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.openbas.rest.collector_frontend_error; - -import io.openbas.rest.collector_frontend_error.form.ErrorDetailsInput; -import io.openbas.rest.helper.RestBehavior; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class LogApi extends RestBehavior { - - public static final Logger logger = LoggerFactory.getLogger(LogApi.class); - - @PostMapping("/api/logs/frontend-error") - public void logError(@RequestBody ErrorDetailsInput errorDetails) { - logger.error( - "Message error received: {} stacktrace: {} at {}", - errorDetails.getMessage(), - errorDetails.getStack(), - errorDetails.getTimestamp()); - } -} diff --git a/openbas-api/src/main/java/io/openbas/rest/log/LogApi.java b/openbas-api/src/main/java/io/openbas/rest/log/LogApi.java new file mode 100644 index 0000000000..c4d2999ee1 --- /dev/null +++ b/openbas-api/src/main/java/io/openbas/rest/log/LogApi.java @@ -0,0 +1,49 @@ +package io.openbas.rest.log; + +import io.openbas.rest.helper.RestBehavior; +import io.openbas.rest.log.form.LogDetailsInput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class LogApi extends RestBehavior { + + public static final Logger logger = LoggerFactory.getLogger(LogApi.class); + + @PostMapping("/api/logs") + public void logDetails(@RequestBody LogDetailsInput logDetailsInput) { + switch (logDetailsInput.getLevel()) { + case "WARN": + logger.warn( + "Message warn received: {} stacktrace: {} at {}", + logDetailsInput.getMessage(), + logDetailsInput.getStack(), + logDetailsInput.getTimestamp()); + break; + case "INFO": + logger.info( + "Message info received: {} stacktrace: {} at {}", + logDetailsInput.getMessage(), + logDetailsInput.getStack(), + logDetailsInput.getTimestamp()); + break; + case "DEBUG": + logger.debug( + "Message debug received: {} stacktrace: {} at {}", + logDetailsInput.getMessage(), + logDetailsInput.getStack(), + logDetailsInput.getTimestamp()); + break; + default: + logger.error( + "Message error received: {} stacktrace: {} at {}", + logDetailsInput.getMessage(), + logDetailsInput.getStack(), + logDetailsInput.getTimestamp()); + break; + } + } +} diff --git a/openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/form/ErrorDetailsInput.java b/openbas-api/src/main/java/io/openbas/rest/log/form/LogDetailsInput.java similarity index 61% rename from openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/form/ErrorDetailsInput.java rename to openbas-api/src/main/java/io/openbas/rest/log/form/LogDetailsInput.java index 7e3bc5eb61..d2fedf6150 100644 --- a/openbas-api/src/main/java/io/openbas/rest/collector_frontend_error/form/ErrorDetailsInput.java +++ b/openbas-api/src/main/java/io/openbas/rest/log/form/LogDetailsInput.java @@ -1,13 +1,14 @@ -package io.openbas.rest.collector_frontend_error.form; +package io.openbas.rest.log.form; import lombok.Getter; import lombok.Setter; @Getter @Setter -public class ErrorDetailsInput { +public class LogDetailsInput { private String message; private String stack; private String timestamp; + private String level; } diff --git a/openbas-front/src/utils/Action.ts b/openbas-front/src/utils/Action.ts index 800703662d..af2366aba4 100644 --- a/openbas-front/src/utils/Action.ts +++ b/openbas-front/src/utils/Action.ts @@ -216,8 +216,9 @@ export const sendErrorToBackend = async (error: Error, stack: ErrorInfo) => { message: error.message, stack: stack.componentStack, timestamp: new Date().toISOString(), + level: 'ERROR', }; - simplePostCall('/api/logs/frontend-error', errorDetails) + simplePostCall('/api/logs/', errorDetails) .then((response) => { notifySuccess('Error successfully sent to backend:' + response); })