mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-06 17:08:27 +08:00
feat: 支持配置日志级别
This commit is contained in:
parent
19bf4c6811
commit
afca393473
@ -21,4 +21,5 @@ public class MilvusPropertiesConfiguration {
|
||||
private String token;
|
||||
private List<String> packages;
|
||||
private boolean openLog;
|
||||
private String logLevel;
|
||||
}
|
||||
@ -24,7 +24,11 @@ public class MilvusInit extends AbstractMilvusClientBuilder {
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
printBanner();
|
||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus", milvusPropertiesConfiguration.isOpenLog());
|
||||
|
||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
||||
milvusPropertiesConfiguration.isOpenLog(),
|
||||
milvusPropertiesConfiguration.getLogLevel());
|
||||
|
||||
MilvusProperties milvusProperties = new MilvusProperties();
|
||||
BeanUtils.copyProperties(milvusPropertiesConfiguration, milvusProperties);
|
||||
super.setProperties(milvusProperties);
|
||||
|
||||
@ -11,6 +11,7 @@ public class LogLevelController {
|
||||
|
||||
/**
|
||||
* 设置特定包下所有类的日志级别。
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @param level 日志级别
|
||||
*/
|
||||
@ -25,11 +26,16 @@ public class LogLevelController {
|
||||
/**
|
||||
* 动态设置日志开关。
|
||||
* 当设置为Level.OFF时,等同于关闭日志。
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @param enabled 是否启用日志
|
||||
*/
|
||||
public static void setLoggingEnabledForPackage(String packageName, boolean enabled) {
|
||||
Level level = enabled ? Level.DEBUG : Level.OFF; // 可以根据需要设置为INFO, WARN, ERROR等
|
||||
setLogLevelForPackage(packageName, level);
|
||||
public static void setLoggingEnabledForPackage(String packageName, boolean enabled, String level) {
|
||||
// 开启日志 默认 -> debug
|
||||
if (enabled) {
|
||||
setLogLevelForPackage(packageName, Level.toLevel(level, Level.DEBUG));
|
||||
} else {
|
||||
setLogLevelForPackage(packageName, Level.OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,4 +21,5 @@ public class MilvusPropertiesConfiguration {
|
||||
private String token;
|
||||
private List<String> packages;
|
||||
private boolean openLog;
|
||||
private String logLevel;
|
||||
}
|
||||
@ -17,7 +17,9 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Lifecycle
|
||||
@Bean
|
||||
public MilvusClientV2 init(MilvusPropertiesConfiguration milvusPropertiesConfiguration) {
|
||||
printBanner();
|
||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus", milvusPropertiesConfiguration.isOpenLog());
|
||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
||||
milvusPropertiesConfiguration.isOpenLog(),
|
||||
milvusPropertiesConfiguration.getLogLevel());
|
||||
MilvusProperties milvusProperties = new MilvusProperties();
|
||||
BeanUtils.copyProperties(milvusPropertiesConfiguration, milvusProperties);
|
||||
super.setProperties(milvusProperties);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user