Logging system enhanced (#124)
Co-authored-by: mikolaj widla <mikolaj.widla@gmail.com> Reviewed-on: #124 Co-authored-by: Mikolaj Widla <widlam@noreply.example.com> Co-committed-by: Mikolaj Widla <widlam@noreply.example.com>
This commit is contained in:
		| @@ -2,19 +2,17 @@ package com.r11.tools.controller; | ||||
|  | ||||
| import com.r11.tools.model.EventRequestDto; | ||||
| import com.r11.tools.service.EtrackService; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.UUID; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.UUID; | ||||
|  | ||||
| /** | ||||
|  * It's the REST api for {@link com.r11.tools.model.Event} | ||||
|  * @author Gabriel Modzelewski | ||||
|  */ | ||||
| @Slf4j | ||||
| @RestController | ||||
| @RequestMapping(path = "/api/event") | ||||
| @AllArgsConstructor | ||||
|   | ||||
| @@ -7,7 +7,8 @@ import com.r11.tools.utilis.BusinessKey; | ||||
| import com.r11.tools.utilis.TrackingClient; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.SneakyThrows; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.springframework.http.*; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| @@ -18,14 +19,17 @@ import java.util.*; | ||||
|  * Returns the homepage and provides the api for javascript async requests. | ||||
|  * @author Gabriel Modzelewski | ||||
|  */ | ||||
| @Slf4j | ||||
| @RestController | ||||
| @RequestMapping(path = "/api/mock") | ||||
| @AllArgsConstructor | ||||
| public class MockController { | ||||
|     private final KlausService klausService; | ||||
|     private final Logger log = LogManager.getRootLogger(); | ||||
|  | ||||
|  | ||||
|     @ExceptionHandler(Exception.class) | ||||
|     public void errorHandler(Exception ex){ | ||||
|         log.error(ex.getStackTrace()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Updates queried message with given set of data | ||||
| @@ -77,10 +81,13 @@ public class MockController { | ||||
|         try{ | ||||
|             UUID.fromString(givenUUIDValue); | ||||
|         } catch (IllegalArgumentException ex){ | ||||
|             log.error("Wrong UUID value!"); | ||||
|             if (previousUUIDValue == null || previousUUIDValue.equals("")){ | ||||
|                 UUID newUUID = UUID.randomUUID(); | ||||
|                 log.info("New UUID generated."); | ||||
|                 return ResponseEntity.ok(newUUID.toString()); | ||||
|             } | ||||
|             log.info("Previous UUID value restored."); | ||||
|             return ResponseEntity.ok(previousUUIDValue); | ||||
|         } | ||||
|         return ResponseEntity.ok(givenUUIDValue); | ||||
| @@ -180,7 +187,7 @@ public class MockController { | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - request", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|         log.info(requestEntity.toString().replaceAll("\"", "\\\\\"").substring(1)); | ||||
|         // log.info(requestEntity.toString().replaceAll("\"", "\\\\\"").substring(1).replaceAll("\n","")); | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - response", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|   | ||||
| @@ -4,20 +4,19 @@ import com.r11.tools.model.Event; | ||||
| import com.r11.tools.model.EventRequestDto; | ||||
| import com.r11.tools.repository.EventRepository; | ||||
| import com.r11.tools.utilis.BusinessKey; | ||||
| import lombok.AllArgsConstructor; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| /** | ||||
|  * Spring Service for {@link com.r11.tools.controller.EventController}. Contains logic required for quering | ||||
|  * the database for {@link Event} objects | ||||
|  * @author Rafał Żukowicz | ||||
|  */ | ||||
| @Slf4j | ||||
| @Service | ||||
| @AllArgsConstructor | ||||
| public class EtrackServiceImpl implements EtrackService { | ||||
|   | ||||
| @@ -7,7 +7,8 @@ import com.r11.tools.model.MockedMessageDto; | ||||
| import com.r11.tools.repository.MockedResponseRepository; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.SneakyThrows; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.springframework.http.HttpHeaders; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| @@ -23,11 +24,11 @@ import java.util.stream.Collectors; | ||||
|  * @author Rafał Żukowicz | ||||
|  * @author Gabriel Modzelewski | ||||
|  */ | ||||
| @Slf4j | ||||
| @Service | ||||
| @AllArgsConstructor | ||||
| public class KlausServiceImpl implements KlausService { | ||||
|     private final MockedMessageMapper mockedMessageMapper; | ||||
|     private final Logger log = LogManager.getRootLogger(); | ||||
|     private final MockedResponseRepository mockedResponseRepository; | ||||
|     private final ObjectMapper objectMapper; | ||||
|  | ||||
| @@ -41,7 +42,7 @@ public class KlausServiceImpl implements KlausService { | ||||
|     public ResponseEntity<String> deleteMockedResponse(UUID clientUUID, int mockedResponseId) { | ||||
|         String key = clientUUID.toString() + "_" + mockedResponseId; | ||||
|         mockedResponseRepository.deleteById(key); | ||||
|         log.info("Message " + mockedResponseId + " has been removed."); | ||||
|         log.info("Message: "+mockedResponseId+" has been removed."); | ||||
|         return new ResponseEntity<>("MockedResponse has been removed successfully", | ||||
|                 new HttpHeaders(), HttpStatus.ACCEPTED); | ||||
|     } | ||||
| @@ -54,6 +55,7 @@ public class KlausServiceImpl implements KlausService { | ||||
|     @Override | ||||
|     public List<MockedMessageDto> getAllMockedResponses(UUID clientUUID){ | ||||
|         Optional<List<MockedMessage>> listOptional = mockedResponseRepository.findAllByClientUUID(clientUUID); | ||||
|         log.info("Messages for UUID: "+clientUUID+" has been fetched from DB."); | ||||
|         return listOptional.map(mockedMessages -> mockedMessages.stream() | ||||
|                 .map(mockedMessageMapper::mockedMessageToMockedMessageDto) | ||||
|                 .collect(Collectors.toList())).orElse(List.of()); | ||||
| @@ -76,10 +78,10 @@ public class KlausServiceImpl implements KlausService { | ||||
|                 .build(); | ||||
|         if (optionalMockedMessage.isPresent()) { | ||||
|             mockedMessageDto = mockedMessageMapper.mockedMessageToMockedMessageDto(optionalMockedMessage.get()); | ||||
|             log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|             //log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|             return mockedMessageDto; | ||||
|         } | ||||
|         log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|         //log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|         return mockedMessageDto; | ||||
|     } | ||||
|  | ||||
| @@ -92,7 +94,7 @@ public class KlausServiceImpl implements KlausService { | ||||
|     @Override | ||||
|     public ResponseEntity<String> setMockedResponse(MockedMessageDto mockedMessageDto) { | ||||
|         mockedResponseRepository.save(mockedMessageMapper.mockedMessageDtoToMockedMessage(mockedMessageDto)); | ||||
|         log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|         //log.info(mockedMessageDto.toString().replaceAll("\"", "\\\\\"")); | ||||
|         return new ResponseEntity<>("MockedResponse has been setup successfully!", new HttpHeaders(), | ||||
|                 HttpStatus.ACCEPTED); | ||||
|     } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <configuration> | ||||
|     <include resource="org/springframework/boot/logging/logback/base.xml"/> | ||||
|     <property name="HOME_LOG" value="/log/mockServices.log"/> | ||||
|     <!--https://github.com/kmtong/logback-redis-appender--> | ||||
|     <appender name="LOGSTASH" class="com.r11.tools.utilis.RedisAppender"> | ||||
|         <host>redis</host> | ||||
| @@ -16,6 +17,22 @@ | ||||
|     <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> | ||||
|         <appender-ref ref="LOGSTASH" /> | ||||
|     </appender> | ||||
|  | ||||
|     <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||||
|         <file>${HOME_LOG}</file> | ||||
|  | ||||
|         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | ||||
|             <fileNamePattern>logs/mockServices.%d{yyyy-MM-dd}.%i.log</fileNamePattern> | ||||
|             <maxFileSize>10MB</maxFileSize> | ||||
|             <totalSizeCap>20GB</totalSizeCap> | ||||
|             <maxHistory>60</maxHistory> | ||||
|         </rollingPolicy> | ||||
|  | ||||
|         <encoder> | ||||
|             <pattern>%d %p %c{1.} [%t] %m%n</pattern> | ||||
|         </encoder> | ||||
|     </appender> | ||||
|  | ||||
|     <root level="DEBUG"> | ||||
|         <appender-ref ref="ASYNC" /> | ||||
|         <appender-ref ref="CONSOLE" /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user