65 lines
2.7 KiB
Java
65 lines
2.7 KiB
Java
package com.eactive.eai.common.logger;
|
|
|
|
import java.util.List;
|
|
|
|
import com.eactive.eai.common.logger.mapper.HttpAdapterExtraLogMapper;
|
|
import com.eactive.eai.common.util.Logger;
|
|
import com.eactive.eai.data.entity.onl.logger.HttpAdapterExtraLog;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@Service
|
|
public class HttpLoggingService {
|
|
|
|
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
|
|
|
@Autowired
|
|
private HttpAdapterExtraLogMapper mapper;
|
|
|
|
@Autowired
|
|
private HttpAdapterExtraLogLogger dbLogger;
|
|
|
|
@Autowired
|
|
private HttpAdapterExtraLogFileLogger fileLogger;
|
|
|
|
/**
|
|
* 여러 건을 한 트랜잭션(COMMIT 1회)으로 적재한다.
|
|
* HttpAdapterExtraLogLogger가 @Transactional(REQUIRED)이므로 이 트랜잭션에 합류한다.
|
|
*
|
|
* 배치 중 한 건이라도 실패하면 전체가 롤백되므로,
|
|
* 호출측에서 insertHttpAdapterExtraLog()로 건별 재시도해야 한다.
|
|
*/
|
|
@Transactional
|
|
public void insertHttpAdapterExtraLogBatch(List<HttpAdapterExtraLogVo> voList) throws Throwable {
|
|
for (HttpAdapterExtraLogVo vo : voList) {
|
|
dbLogger.save(mapper.toEntity(vo));
|
|
}
|
|
}
|
|
|
|
public void insertHttpAdapterExtraLog(HttpAdapterExtraLogVo httpAdapterExtraLogVo) throws Throwable{
|
|
HttpAdapterExtraLog httpAdapterExtraLog = mapper.toEntity(httpAdapterExtraLogVo);
|
|
if (EAIDBLogControl.isEnable()) {
|
|
try {
|
|
dbLogger.save(httpAdapterExtraLog);
|
|
logger.debug("inserted to DB");
|
|
} catch(Exception e){
|
|
String message = e.getMessage();
|
|
// 오류 메시지 추가 - Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
|
|
// 오류 메시지 추가 - Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
|
|
if( "ConnectionError".equals(message) || StringUtils.contains(message, "JDBCConnectionException")
|
|
|| StringUtils.contains(message, "Unable to acquire JDBC Connection") ) {
|
|
EAIDBLogControl.setEnable(false);
|
|
}
|
|
fileLogger.writeFileLog(httpAdapterExtraLog);
|
|
logger.debug("wrote to File");
|
|
}
|
|
} else {
|
|
fileLogger.writeFileLog(httpAdapterExtraLog);
|
|
logger.debug("wrote to File");
|
|
}
|
|
}
|
|
}
|