Skip to content

Commit

Permalink
Merge pull request #9 from KepLer100500/logs
Browse files Browse the repository at this point in the history
Change default logger to slf4j.
  • Loading branch information
KepLer100500 authored Jul 11, 2023
2 parents db87c0e + 4580e9c commit 156bc75
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Dialog/src/main/java/com/kepler/controller/AliceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import com.kepler.model.response.Response;
import com.kepler.proxy.RabbitConsumer;
import com.kepler.proxy.RabbitProducer;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Log
@Slf4j
@RestController
@RequestMapping ("darts/api/v1/") // url for alice dialog webhook
public class AliceDialog {
Expand All @@ -34,7 +34,7 @@ public OutputData entryPoint(@RequestBody InputData inputData) {
OutputData outputData = buildOutputData(inputData);
Integer summaryPoints = sendTextAndReceiveCalculatedPoints(inputData.getRequest().getNlu().getTokens());
Response response = buildResponse(summaryPoints);

log.info("Send to dialog: {}", summaryPoints);
outputData.setResponse(response);
return outputData;
}
Expand Down
7 changes: 3 additions & 4 deletions Dialog/src/main/java/com/kepler/proxy/RabbitConsumer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.kepler.proxy;

import com.kepler.model.ResultCalculations;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.logging.Level;
import org.springframework.amqp.support.converter.MessageConverter;

@Service
@Log
@Slf4j
public class RabbitConsumer {
@Value("${rabbitmq.queue.dialog}")
private String queueDialog;
Expand All @@ -28,7 +27,7 @@ public class RabbitConsumer {
public ResultCalculations receiveMessage() {
rabbitTemplate.setMessageConverter(jsonMessageConverter);
ResultCalculations result = (ResultCalculations)rabbitTemplate.receiveAndConvert(queueDialog, 1000);
log.log(Level.INFO, "Receive message: {0}", result);
log.info("Receive message: {}", result);
return result;
}
}
7 changes: 3 additions & 4 deletions Dialog/src/main/java/com/kepler/proxy/RabbitProducer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.kepler.proxy;

import com.kepler.model.Tokens;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.logging.Level;


@Service
@Log
@Slf4j
public class RabbitProducer {
@Value("${rabbitmq.exchange}")
private String exchange;
Expand All @@ -30,7 +29,7 @@ public class RabbitProducer {
* @param tokens
*/
public void sendMessage(Tokens tokens) {
log.log(Level.INFO, "Sending message: {0}", tokens);
log.info("Sending message: {}", tokens);

rabbitTemplate.setMessageConverter(jsonMessageConverter);
rabbitTemplate.convertAndSend(
Expand Down
19 changes: 19 additions & 0 deletions Dialog/src/main/resources/application.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ rabbitmq.queue.dialog=
rabbitmq.routingKey.dialog=
rabbitmq.queue.game=
rabbitmq.routingKey.game=

# log level
logging.level.root=INFO
# how named log file
logging.file.name=logs/app.log
# pattern to log oversize
logging.logback.rollingpolicy.file-name-pattern=logs/%d{dd-MM-yyyy}/app-%d{dd-MM-yyyy}-%i.log
# size one file before rotate
logging.logback.rollingpolicy.max-file-size=100KB
# how many days by rotate logs
logging.logback.rollingpolicy.max-history=30
# total size of backup log
logging.logback.rollingpolicy.total-size-cap=10MB
# auto-clear on start
logging.logback.rollingpolicy.clean-history-on-start=true
# how write logs to console
logging.pattern.console=%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
# how write logs to file
logging.pattern.file=%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
8 changes: 3 additions & 5 deletions Game/src/main/java/com/kepler/proxy/RabbitConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import com.kepler.model.ResultCalculations;
import com.kepler.model.Tokens;
import com.kepler.service.PointsCalculator;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.logging.Level;


@Service
@EnableRabbit
@Log
@Slf4j
public class RabbitConsumer {
@Autowired
RabbitProducer rabbitProducer;
Expand All @@ -32,7 +30,7 @@ public void processQueue(Tokens tokens) {
.resultCalculations(
pointsCalculator.process(tokens.getTokens())
).build();
log.log(Level.INFO, "Calculations done, result: {0}", result.getResultCalculations());
log.info("Calculations done, result: {}", result.getResultCalculations());
rabbitProducer.sendMessage(result);
}
}
2 changes: 2 additions & 0 deletions Game/src/main/java/com/kepler/proxy/RabbitProducer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kepler.proxy;

import com.kepler.model.ResultCalculations;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,6 +10,7 @@


@Service
@Slf4j
public class RabbitProducer {
@Value("${rabbitmq.exchange}")
private String exchange;
Expand Down
4 changes: 2 additions & 2 deletions Game/src/main/java/com/kepler/service/PointsCalculator.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.kepler.service;

import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;


@Log
@Slf4j
@Service
public class PointsCalculator {
/**
Expand Down
19 changes: 19 additions & 0 deletions Game/src/main/resources/application.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ rabbitmq.queue.dialog=
rabbitmq.routingKey.dialog=
rabbitmq.queue.game=
rabbitmq.routingKey.game=

# log level
logging.level.root=INFO
# how named log file
logging.file.name=logs/app.log
# pattern to log oversize
logging.logback.rollingpolicy.file-name-pattern=logs/%d{dd-MM-yyyy}/app-%d{dd-MM-yyyy}-%i.log
# size one file before rotate
logging.logback.rollingpolicy.max-file-size=100KB
# how many days by rotate logs
logging.logback.rollingpolicy.max-history=30
# total size of backup log
logging.logback.rollingpolicy.total-size-cap=10MB
# auto-clear on start
logging.logback.rollingpolicy.clean-history-on-start=true
# how write logs to console
logging.pattern.console=%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
# how write logs to file
logging.pattern.file=%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
4 changes: 2 additions & 2 deletions Game/src/test/java/com/kepler/PointsCalculatorTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.kepler;

import com.kepler.service.PointsCalculator;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.*;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@DisplayName("Test case: calculate sum player points")
@Log
@Slf4j
@SpringBootTest
public class PointsCalculatorTest {
@Autowired
Expand Down

0 comments on commit 156bc75

Please sign in to comment.