opt: lucene日志

This commit is contained in:
2024-01-10 16:55:25 +08:00
parent a7358e420e
commit cd5c04acab
9 changed files with 54 additions and 11 deletions

View File

@@ -0,0 +1,28 @@
package org.nl.common.utils;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.util.Properties;
/**
* @Author: lyd
* @Description: 配置文件获取方法
* @Date: 2023/12/6
*/
public class YmlConfigFileUtil {
public static Properties readConfig(String configFile) {
// 创建 Resource 对象
Resource resource = new ClassPathResource(configFile);
// 创建 YamlPropertiesFactoryBean
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
yamlPropertiesFactoryBean.setResources(resource);
// 获取 Properties 对象
Properties properties = yamlPropertiesFactoryBean.getObject();
return properties;
}
}

View File

@@ -16,11 +16,13 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.nl.common.utils.YmlConfigFileUtil;
import org.wltea.analyzer.lucene.IKAnalyzer;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Properties;
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
@@ -32,7 +34,11 @@ public class LuceneAppender extends AppenderBase<ILoggingEvent> {
public void start() {
super.start();
try {
index = FSDirectory.open(Paths.get(LogMessageConstant.INDEX_DIR));
// 读取配置文件
Properties properties = YmlConfigFileUtil.readConfig("config/application.yml");
String luceneDir = properties.getProperty("lucene.index.path");
index = FSDirectory.open(Paths.get(luceneDir));
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -80,5 +80,7 @@ public class MdBaseBrickInfo implements Serializable {
@ApiModelProperty(value = "工单号")
private String workorder_code;
@ApiModelProperty(value = "故障原因")
private String error_cause;
}

View File

@@ -120,6 +120,7 @@ public class MdBaseBrickInfoServiceImpl extends ServiceImpl<MdBaseBrickInfoMappe
brickInfo.setFlatness(dto.getFlatness());
brickInfo.setUnqualified_qty(dto.getUnqualified_qty());
brickInfo.setIs_group(false);
brickInfo.setError_cause(dto.getError_cause());
return brickInfo;
}

View File

@@ -42,4 +42,6 @@ public class BrickInfoDto extends BaseRequest {
private String flatness;
/** 缺陷个数 **/
private String unqualified_qty;
/** 故障原因 */
private String error_cause;
}

View File

@@ -137,7 +137,3 @@ sa-token:
password:
# 连接超时时间
timeout: 10s
lucene:
index:
path: D:\lucene\index

View File

@@ -172,6 +172,3 @@ sa-token:
password:
# 连接超时时间
timeout: 10s
lucene:
index:
path: E:\lucene\index

View File

@@ -129,3 +129,7 @@ mybatis-plus:
global-config:
db-config:
id-type: INPUT
lucene:
index:
path: D:\lucene\index

View File

@@ -26,6 +26,13 @@ https://juejin.cn/post/6844903775631572999
<!-- <charset>${log.charset}</charset>-->
</encoder>
</appender>
<appender name="luceneAppender" class="org.nl.config.lucene.LuceneAppender" >
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${logPath}"/>
@@ -62,9 +69,9 @@ https://juejin.cn/post/6844903775631572999
</appender>
<!--开发环境:打印控制台-->
<springProfile name="dev">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<root level="DEBUG">
<appender-ref ref="asyncLuceneAppender"/>
<appender-ref ref="CONSOLE"/>
</root>
<logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
@@ -107,7 +114,7 @@ https://juejin.cn/post/6844903775631572999
<!--生产环境:打印控制台和输出到文件-->
<springProfile name="prod">
<root level="INFO">
<root level="DEBUG">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="asyncLuceneAppender"/>
</root>