opt:日志优化
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
/**
|
||||||
|
* @author ldjun
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023年08月24日 13:00
|
||||||
|
* @desc desc
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import com.yomahub.tlog.core.enhance.logback.async.AspectLogbackAsyncAppender;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class AsyncLuceneAppender extends AspectLogbackAsyncAppender {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void append(ILoggingEvent event) {
|
||||||
|
String traceId = LuceneAppender.traceIdTL.get();
|
||||||
|
if (StringUtils.isNotEmpty(traceId)){
|
||||||
|
MDC.put("traceId",traceId);
|
||||||
|
Map<String, String> mdcPropertyMap = event.getMDCPropertyMap();
|
||||||
|
if (mdcPropertyMap.getClass().getName().contains("SynchronizedMap")){
|
||||||
|
mdcPropertyMap.put("traceId",traceId);
|
||||||
|
}
|
||||||
|
MDC.clear();
|
||||||
|
}
|
||||||
|
super.append(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description: 定义lucene相关常量
|
||||||
|
* @Date: 2023/8/25
|
||||||
|
*/
|
||||||
|
public class LogMessageConstant {
|
||||||
|
/** */
|
||||||
|
public final static String SORT_NAME = "time";
|
||||||
|
/** 级别 */
|
||||||
|
public final static String FIELD_LEVEL = "level";
|
||||||
|
/** 时间 */
|
||||||
|
public final static String FIELD_TIMESTAMP = "timestamp";
|
||||||
|
/** 类的限定名 */
|
||||||
|
public final static String FIELD_CLASS_NAME = "logger";
|
||||||
|
/** 线程名 */
|
||||||
|
public final static String FIELD_THREAD = "thread";
|
||||||
|
/** 日志内容 */
|
||||||
|
public final static String FIELD_MESSAGE = "message";
|
||||||
|
public final static String FIELD_TRACEID = "tlogTraceId";
|
||||||
|
// 定义颜色值
|
||||||
|
/** 文本颜色:黑色 */
|
||||||
|
public final static String COLOR_BLACK = "\u001B[30m";
|
||||||
|
/** 文本颜色:红色 */
|
||||||
|
public final static String COLOR_RED = "\u001B[31m";
|
||||||
|
/** 文本颜色:绿色 */
|
||||||
|
public final static String COLOR_GREEN = "\u001B[32m";
|
||||||
|
/** 文本颜色:黄色 */
|
||||||
|
public final static String COLOR_YELLOW = "\u001B[33m";
|
||||||
|
/** 文本颜色:蓝色 */
|
||||||
|
public final static String COLOR_BLUE = "\u001B[34m";
|
||||||
|
/** 文本颜色:品红色 */
|
||||||
|
public final static String COLOR_MAGENTA = "\u001B[35m";
|
||||||
|
/** 文本颜色:青色 */
|
||||||
|
public final static String COLOR_CYAN = "\u001B[36m";
|
||||||
|
/** 文本颜色:白色 */
|
||||||
|
public final static String COLOR_WHITE = "\u001B[37m";
|
||||||
|
/** 文本颜色重置 */
|
||||||
|
public final static String COLOR_RESET = "\u001B[0m";
|
||||||
|
/** 背景颜色:黄色 */
|
||||||
|
public final static String BACKGROUND_YELLOW = "\u001B[43m";
|
||||||
|
/** 索引路径 */
|
||||||
|
public final static String INDEX_DIR = "E:\\lucene\\index";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
/**
|
||||||
|
* @author ldjun
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023年08月24日 13:00
|
||||||
|
* @desc desc
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.AppenderBase;
|
||||||
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.document.*;
|
||||||
|
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.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
||||||
|
|
||||||
|
public static final TransmittableThreadLocal<String> traceIdTL = new TransmittableThreadLocal();
|
||||||
|
public LuceneProperties properties;
|
||||||
|
public static Directory index;
|
||||||
|
private List<LucenePropertyAndEncoder> encoders;
|
||||||
|
public static IndexWriter indexWriter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
super.start();
|
||||||
|
try {
|
||||||
|
init();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() throws IOException {
|
||||||
|
Resource resource = new ClassPathResource("config/application.yml");
|
||||||
|
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
|
||||||
|
yamlPropertiesFactoryBean.setResources(resource);
|
||||||
|
Properties properties = yamlPropertiesFactoryBean.getObject();
|
||||||
|
// 获取配置值
|
||||||
|
String luceneDir = properties.getProperty("lucene.index.path");
|
||||||
|
System.out.println("---index地址----"+luceneDir);
|
||||||
|
index = FSDirectory.open(Paths.get(luceneDir));
|
||||||
|
// 初始化 Lucene 索引
|
||||||
|
Analyzer analyzer = new IKAnalyzer();
|
||||||
|
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||||
|
indexWriter = new IndexWriter(index, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void append(ILoggingEvent event) {
|
||||||
|
Document doc = new Document();
|
||||||
|
for (Property property : this.properties.getProperties()) {
|
||||||
|
LucenePropertyAndEncoder encoder = new LucenePropertyAndEncoder(property, this.context);
|
||||||
|
String encode = encoder.encode(event);
|
||||||
|
doc.add(new StringField(property.getName(), encode, Field.Store.YES));
|
||||||
|
}
|
||||||
|
Map<String, String> map = event.getMDCPropertyMap();
|
||||||
|
if (!map.isEmpty() && StringUtils.isNotEmpty(map.get("traceId"))){
|
||||||
|
doc.add(new StringField("traceId",map.get("traceId"), Field.Store.YES));
|
||||||
|
}else {
|
||||||
|
doc.add(new StringField("traceId"," ", Field.Store.YES));
|
||||||
|
}
|
||||||
|
doc.add(new TextField(LogMessageConstant.FIELD_MESSAGE, event.getFormattedMessage(), Field.Store.YES));
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_CLASS_NAME, event.getLoggerName(), Field.Store.YES));
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_TIMESTAMP, String.valueOf(event.getTimeStamp()),Field.Store.YES));
|
||||||
|
doc.add(new NumericDocValuesField(LogMessageConstant.SORT_NAME, event.getTimeStamp()));
|
||||||
|
try {
|
||||||
|
indexWriter.addDocument(doc);
|
||||||
|
indexWriter.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
|
try {
|
||||||
|
indexWriter.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(LuceneProperties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LuceneProperties {
|
||||||
|
|
||||||
|
private List<Property> properties;
|
||||||
|
|
||||||
|
public LuceneProperties() {
|
||||||
|
this.properties = new ArrayList<Property>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Property> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProperty(Property property) {
|
||||||
|
properties.add(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.PatternLayout;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.Context;
|
||||||
|
import ch.qos.logback.core.pattern.PatternLayoutBase;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2023/12/22 18:11
|
||||||
|
*/
|
||||||
|
public class LucenePropertyAndEncoder {
|
||||||
|
|
||||||
|
private Property property;
|
||||||
|
|
||||||
|
private PatternLayoutBase layout = new PatternLayout();
|
||||||
|
|
||||||
|
public LucenePropertyAndEncoder(Property property, Context context) {
|
||||||
|
this.property = property;
|
||||||
|
this.layout.setContext(context);
|
||||||
|
this.layout.setPattern(String.valueOf(property.getValue()));
|
||||||
|
this.layout.setPostCompileProcessor(null);
|
||||||
|
this.layout.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String encode(ILoggingEvent event) {
|
||||||
|
return layout.doLayout(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return property.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean allowEmpty() {
|
||||||
|
return property.isAllowEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package org.nl.config.lucene;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2023/12/26 15:30
|
||||||
|
*/
|
||||||
|
public class Property {
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private boolean allowEmpty;
|
||||||
|
|
||||||
|
public Property() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Property(String name, String value, boolean allowEmpty) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
this.allowEmpty = allowEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllowEmpty() {
|
||||||
|
return allowEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowEmpty(boolean allowEmpty) {
|
||||||
|
this.allowEmpty = allowEmpty;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
lms/nladmin-system/src/main/resources/IKAnalyzer.cfg.xml
Normal file
11
lms/nladmin-system/src/main/resources/IKAnalyzer.cfg.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties>
|
||||||
|
<comment>IK Analyzer 扩展配置</comment>
|
||||||
|
<!--用户可以在这里配置自己的扩展字典 -->
|
||||||
|
<entry key="ext_dict">ext.dic;</entry>
|
||||||
|
|
||||||
|
<!--用户可以在这里配置自己的扩展停止词字典-->
|
||||||
|
<entry key="ext_stopwords">stopword.dic;</entry>
|
||||||
|
|
||||||
|
</properties>
|
||||||
30
lms/nladmin-system/src/main/resources/ext.dic
Normal file
30
lms/nladmin-system/src/main/resources/ext.dic
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
定时插入半成品实时库存失败的数据
|
||||||
|
插入窑内失败的数据
|
||||||
|
插入窑内失败的信息
|
||||||
|
定时插入半成品实时库存失败的信息
|
||||||
|
插入货架数据失败的数据
|
||||||
|
插入货架数据失败的信息
|
||||||
|
插入窑前失败的数据
|
||||||
|
插入窑前失败的信息
|
||||||
|
获取MES给的工单数据
|
||||||
|
上报mes消耗泥料记录的数据
|
||||||
|
上报mes消耗泥料记录失败
|
||||||
|
压机产出-获取MES给的工单数据
|
||||||
|
压机产出返给MES的数据
|
||||||
|
反馈压机产出插入mes数据库失败
|
||||||
|
半成品入库-获取MES给的工单数据
|
||||||
|
半成品入库返给MES的数据
|
||||||
|
半成品入库插入mes数据库失败
|
||||||
|
半成品出库-获取MES给的工单数据
|
||||||
|
半成品出库返给MES的数据
|
||||||
|
半成品出库插入mes数据库失败
|
||||||
|
压机产出-获取MES给的工单数据
|
||||||
|
压机产出返给MES的数据
|
||||||
|
反馈压机产出插入mes数据库失败
|
||||||
|
插入压机检测失败
|
||||||
|
包装数据
|
||||||
|
更新成功:更新数据
|
||||||
|
插入LMS数据库失败
|
||||||
|
记录自动要料信息
|
||||||
|
自动下发混碾
|
||||||
|
下发混碾失败
|
||||||
1242
lms/nladmin-system/src/main/resources/stopword.dic
Normal file
1242
lms/nladmin-system/src/main/resources/stopword.dic
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user