feat(sync): 增加日志输出
This commit is contained in:
@@ -11,6 +11,7 @@ import com.lanyuanxiaoyao.service.common.utils.RecordHelper;
|
||||
import com.lanyuanxiaoyao.service.common.utils.TableMetaHelper;
|
||||
import com.lanyuanxiaoyao.service.sync.configuration.GlobalConfiguration;
|
||||
import com.lanyuanxiaoyao.service.sync.functions.type.TypeConverter;
|
||||
import com.lanyuanxiaoyao.service.sync.utils.ExceptionUtils;
|
||||
import com.lanyuanxiaoyao.service.sync.utils.JacksonUtils;
|
||||
import com.lanyuanxiaoyao.service.sync.utils.MetricsUtils;
|
||||
import com.lanyuanxiaoyao.service.sync.utils.StatusUtils;
|
||||
@@ -94,7 +95,7 @@ public class Record2RowDataFunction extends RichMapFunction<Record, List<RowData
|
||||
Map<String, Object> current = RecordHelper.getCurrentStatement(record);
|
||||
if (Objects.isNull(current)) {
|
||||
logger.error("Record: {}", mapper.writeValueAsString(record));
|
||||
throw new RuntimeException("Current cannot be null");
|
||||
return ExceptionUtils.throwAndPrint(logger, "Current cannot be null");
|
||||
}
|
||||
|
||||
// 如果 update 改变了过滤字段的值也需要先删除
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import com.lanyuanxiaoyao.service.common.entity.TableMeta;
|
||||
import com.lanyuanxiaoyao.service.common.utils.LogHelper;
|
||||
import com.lanyuanxiaoyao.service.sync.utils.ExceptionUtils;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -115,7 +116,8 @@ public class TypeConverterV2 implements TypeConverter {
|
||||
return NULLABLE_STRING_SCHEMA;
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
throw new RuntimeException(
|
||||
return ExceptionUtils.throwAndPrint(
|
||||
logger,
|
||||
StrUtil.format("Convert type failure {} {} {} length: {} scala: {}", table, field, type, length, scala),
|
||||
throwable
|
||||
);
|
||||
@@ -162,7 +164,8 @@ public class TypeConverterV2 implements TypeConverter {
|
||||
return value;
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
throw new RuntimeException(
|
||||
return ExceptionUtils.throwAndPrint(
|
||||
logger,
|
||||
StrUtil.format("Convert value failure {} {} {}", schema.toString(), name, value),
|
||||
throwable
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.lanyuanxiaoyao.service.sync.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* 处理异常抛出和打印
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-10-22
|
||||
*/
|
||||
public class ExceptionUtils {
|
||||
public static <T> T throwAndPrint(Logger logger, String content) {
|
||||
logger.error(content);
|
||||
throw new RuntimeException(content);
|
||||
}
|
||||
|
||||
public static <T> T throwAndPrint(Logger logger, Throwable throwable) {
|
||||
logger.error(throwable.getMessage(), throwable);
|
||||
throw new RuntimeException(throwable);
|
||||
}
|
||||
|
||||
public static <T> T throwAndPrint(Logger logger, String content, Throwable throwable) {
|
||||
logger.error(content, throwable);
|
||||
throw new RuntimeException(content, throwable);
|
||||
}
|
||||
}
|
||||
@@ -75,11 +75,9 @@ public class ZkUtils {
|
||||
.withMode(CreateMode.EPHEMERAL)
|
||||
.forPath(lockPath, runMeta.getBytes());
|
||||
} catch (KeeperException.NodeExistsException e) {
|
||||
logger.error("Lock exists for " + lockPath, e);
|
||||
throw new RuntimeException(e);
|
||||
ExceptionUtils.throwAndPrint(logger, "Lock exists for " + lockPath, e);
|
||||
} catch (Exception e) {
|
||||
logger.error("Unknown error", e);
|
||||
throw new RuntimeException(e);
|
||||
ExceptionUtils.throwAndPrint(logger, "Unknown error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +89,7 @@ public class ZkUtils {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Unknown error", e);
|
||||
throw new RuntimeException(e);
|
||||
ExceptionUtils.throwAndPrint(logger, "Unknown error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user