From 2d13c3e71c1189c57b504cb2202fff72debb6786 Mon Sep 17 00:00:00 2001 From: zhuguanyu Date: Wed, 10 Aug 2022 16:55:56 +0800 Subject: Add logs for uui intent-analysis server Issue-ID: USECASEUI-708 Signed-off-by: zhuguanyu Change-Id: Iab2a9f71a7142f31ca9c3dd7444636ae96b46add --- intentanalysis/pom.xml | 7 +++++++ .../service/impl/ExpectationServiceImpl.java | 23 ++++++++++----------- .../service/impl/IntentServiceImpl.java | 23 ++++++++++----------- .../service/impl/StateServiceImpl.java | 22 +++++++++----------- intentanalysis/src/main/resources/logback.xml | 24 ++++++++++++++++++++++ 5 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 intentanalysis/src/main/resources/logback.xml diff --git a/intentanalysis/pom.xml b/intentanalysis/pom.xml index 56efe9a..e05095c 100644 --- a/intentanalysis/pom.xml +++ b/intentanalysis/pom.xml @@ -75,9 +75,16 @@ test + + ch.qos.logback + logback-classic + 1.2.11 + + org.projectlombok lombok + 1.18.24 diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java index af7a2e9..b8f6c3e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/ExpectationServiceImpl.java @@ -17,6 +17,7 @@ package org.onap.usecaseui.intentanalysis.service.impl; +import lombok.extern.slf4j.Slf4j; import org.onap.usecaseui.intentanalysis.bean.models.Expectation; import org.onap.usecaseui.intentanalysis.bean.models.State; import org.onap.usecaseui.intentanalysis.exception.DataBaseException; @@ -25,8 +26,6 @@ import org.onap.usecaseui.intentanalysis.service.ExpectationService; import org.onap.usecaseui.intentanalysis.service.StateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.onap.usecaseui.intentanalysis.common.ResponseConsts; @@ -34,9 +33,9 @@ import java.util.ArrayList; import java.util.List; @Service +@Slf4j public class ExpectationServiceImpl implements ExpectationService { - private static Logger LOGGER = LoggerFactory.getLogger(ExpectationServiceImpl.class); @Autowired private ExpectationMapper expectationMapper; @@ -56,7 +55,7 @@ public class ExpectationServiceImpl implements ExpectationService { int res = expectationMapper.insertExpectationList(expectationList, intentId); if (res < 1) { String msg = "Create expectation to database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } } @@ -66,7 +65,7 @@ public class ExpectationServiceImpl implements ExpectationService { List expectationList = expectationMapper.selectExpectationByIntentId(intentId); if (expectationList == null) { String msg = String.format("Intent id %s doesn't exist in database.", intentId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } for (Expectation expectation : expectationList) { @@ -81,13 +80,13 @@ public class ExpectationServiceImpl implements ExpectationService { List expectationList = expectationMapper.selectExpectationByIntentId(intentId); if (expectationList == null) { String msg = String.format("Intent id %s doesn't exist in database.", intentId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } int res = expectationMapper.deleteExpectationByIntentId(intentId); if (res < 1) { String msg = "Delete expectation in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); } for (Expectation expectation : expectationList) { @@ -100,7 +99,7 @@ public class ExpectationServiceImpl implements ExpectationService { List expectationDBList = expectationMapper.selectExpectationByIntentId(intentId); if (expectationDBList == null) { String msg = String.format("Intent id %s doesn't exist in database.", intentId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } List expectationDBIdList = new ArrayList<>(); @@ -114,7 +113,7 @@ public class ExpectationServiceImpl implements ExpectationService { int res = expectationMapper.updateExpectation(expectation); if (res < 1) { String msg = "Update expectation in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); } expectationDBIdList.remove(expectation.getExpectationId()); @@ -125,7 +124,7 @@ public class ExpectationServiceImpl implements ExpectationService { for (String expectationDBId : expectationDBIdList) { expectationService.deleteExpectationById(expectationDBId); } - LOGGER.info("Expectations are successfully updated."); + log.info("Expectations are successfully updated."); } @Override @@ -133,7 +132,7 @@ public class ExpectationServiceImpl implements ExpectationService { int res = expectationMapper.insertExpectation(expectation, intentId); if (res < 1) { String msg = "Create expectation to database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } } @@ -143,7 +142,7 @@ public class ExpectationServiceImpl implements ExpectationService { int res = expectationMapper.deleteExpectationById(expectationId); if (res < 1) { String msg = "Delete expectation in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java index 21dfe21..2564c2a 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java @@ -17,12 +17,11 @@ package org.onap.usecaseui.intentanalysis.service.impl; +import lombok.extern.slf4j.Slf4j; import org.onap.usecaseui.intentanalysis.bean.models.Intent; import org.onap.usecaseui.intentanalysis.mapper.IntentMapper; import org.onap.usecaseui.intentanalysis.service.ExpectationService; import org.onap.usecaseui.intentanalysis.service.IntentService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,8 +32,8 @@ import java.util.ArrayList; import java.util.List; @Service +@Slf4j public class IntentServiceImpl implements IntentService { - private static Logger LOGGER = LoggerFactory.getLogger(IntentService.class); @Autowired private IntentMapper intentMapper; @@ -47,7 +46,7 @@ public class IntentServiceImpl implements IntentService { List intentList = intentMapper.selectIntents(); if (intentList == null || intentList.size() <= 0) { String msg = "Intent list doesn't exist in the intent database."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } for (Intent intent : intentList) { @@ -64,7 +63,7 @@ public class IntentServiceImpl implements IntentService { return intent; } else { String msg = String.format("Intent id %s doesn't exist in database.", intentId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } } @@ -75,12 +74,12 @@ public class IntentServiceImpl implements IntentService { int res = intentMapper.insertIntent(intent); if (res < 1) { String msg = "Create intent to database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } // saving expectation list into expectation table expectationService.createExpectationList(intent.getExpectationList(), intent.getIntentId()); - LOGGER.info("Intent was successfully created."); + log.debug("Intent was successfully created."); return intent; } @@ -89,17 +88,17 @@ public class IntentServiceImpl implements IntentService { Intent intentDB = intentMapper.selectIntentById(intent.getIntentId()); if (intentDB == null) { String msg = String.format("Intent id %s doesn't exist in database.", intent.getIntentId()); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } expectationService.updateExpectationListById(intent.getExpectationList(), intent.getIntentId()); int res = intentMapper.updateIntent(intent); if (res < 1) { String msg = "Update intent in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); } - LOGGER.info("Update intent successfully."); + log.debug("Update intent successfully."); return intentMapper.selectIntentById(intent.getIntentId()); } @@ -108,10 +107,10 @@ public class IntentServiceImpl implements IntentService { int res = intentMapper.deleteIntentById(intentId); if (res < 1) { String msg = "Delete intent in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); } expectationService.deleteExpectationListById(intentId); - LOGGER.info("Intent has been deleted successfully."); + log.debug("Intent has been deleted successfully."); } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java index 06fa9fd..5a748d9 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java @@ -17,13 +17,12 @@ package org.onap.usecaseui.intentanalysis.service.impl; +import lombok.extern.slf4j.Slf4j; import org.onap.usecaseui.intentanalysis.bean.models.State; import org.onap.usecaseui.intentanalysis.common.ResponseConsts; import org.onap.usecaseui.intentanalysis.exception.DataBaseException; import org.onap.usecaseui.intentanalysis.mapper.StateMapper; import org.onap.usecaseui.intentanalysis.service.StateService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,10 +30,9 @@ import java.util.ArrayList; import java.util.List; @Service +@Slf4j public class StateServiceImpl implements StateService { - private static Logger LOGGER = LoggerFactory.getLogger(StateServiceImpl.class); - @Autowired private StateMapper stateMapper; @@ -46,7 +44,7 @@ public class StateServiceImpl implements StateService { int res = stateMapper.insertStateList(stateList, expectationId); if (res < 1) { String msg = "Create state to database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } } @@ -56,7 +54,7 @@ public class StateServiceImpl implements StateService { List stateList = stateMapper.selectStateByExpectation(expectationId); if (stateList == null) { String msg = String.format("Expectation id %s doesn't exist in database.", expectationId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } return stateList; @@ -67,7 +65,7 @@ public class StateServiceImpl implements StateService { int res = stateMapper.deleteStateByExpectationId(expectationId); if (res < 1) { String msg = "Delete state in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); } } @@ -77,7 +75,7 @@ public class StateServiceImpl implements StateService { List stateDBList = stateMapper.selectStateByExpectation(expectationId); if (stateDBList == null) { String msg = String.format("Expectation id %s doesn't exist in database.", expectationId); - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); } List stateDBIdList = new ArrayList<>(); @@ -89,7 +87,7 @@ public class StateServiceImpl implements StateService { int res = stateMapper.updateState(state); if (res < 1) { String msg = "Update state in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); } stateDBIdList.remove(state.getStateId()); @@ -100,7 +98,7 @@ public class StateServiceImpl implements StateService { for (String stateDBId : stateDBIdList) { stateService.deleteStateById(stateDBId); } - LOGGER.info("States are successfully updated."); + log.debug("States are successfully updated."); } @Override @@ -108,7 +106,7 @@ public class StateServiceImpl implements StateService { int res = stateMapper.insertState(state, expectationId); if (res < 1) { String msg = "Create state to database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); } } @@ -118,7 +116,7 @@ public class StateServiceImpl implements StateService { int res = stateMapper.deleteStateById(stateId); if (res < 1) { String msg = "Delete state in database failed."; - LOGGER.error(msg); + log.error(msg); throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); } } diff --git a/intentanalysis/src/main/resources/logback.xml b/intentanalysis/src/main/resources/logback.xml new file mode 100644 index 0000000..dc4d415 --- /dev/null +++ b/intentanalysis/src/main/resources/logback.xml @@ -0,0 +1,24 @@ + + + + + System.out + + %d{yyyy-MM-dd HH:mm:ss:SSS} %5p ${PID} --- [%15.15t] %-40.40c{40} : %m%n + + + + + + \ No newline at end of file -- cgit 1.2.3-korg