fix: lucene打印配置
This commit is contained in:
@@ -1,187 +0,0 @@
|
|||||||
package org.nl.config.lucene;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
|
||||||
import org.apache.lucene.document.Document;
|
|
||||||
import org.apache.lucene.document.Field;
|
|
||||||
import org.apache.lucene.document.TextField;
|
|
||||||
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.annotation.Value;
|
|
||||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* lucene索引器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author generator
|
|
||||||
* @since 2023-11-16
|
|
||||||
*/
|
|
||||||
public class Indexer {
|
|
||||||
/**
|
|
||||||
* 写索引实例
|
|
||||||
*/
|
|
||||||
private IndexWriter writer;
|
|
||||||
|
|
||||||
public IndexWriter getWriter() {
|
|
||||||
return writer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造方法,实例化IndexWriter
|
|
||||||
*
|
|
||||||
* @param indexDir
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public Indexer(String indexDir) throws Exception {
|
|
||||||
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
|
||||||
//标准分词器,会自动去掉空格啊,is a the等单词
|
|
||||||
// Analyzer analyzer = new StandardAnalyzer();
|
|
||||||
Analyzer analyzer = new IKAnalyzer();
|
|
||||||
//将标准分词器配到写索引的配置中
|
|
||||||
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
|
||||||
//实例化写索引对象
|
|
||||||
writer = new IndexWriter(dir, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 索引指定目录下的所有文件
|
|
||||||
*
|
|
||||||
* @param dataDir
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public int indexAll(String dataDir) throws Exception {
|
|
||||||
// 获取该路径下的所有文件
|
|
||||||
File[] files = new File(dataDir).listFiles();
|
|
||||||
if (null != files) {
|
|
||||||
for (File file : files) {
|
|
||||||
//调用下面的indexFile方法,对每个文件进行索引
|
|
||||||
indexFile(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//返回索引的文件数
|
|
||||||
return writer.numRamDocs();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 索引指定的文件
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private void indexFile(File file) throws Exception {
|
|
||||||
System.out.println("索引文件的路径:" + file.getCanonicalPath());
|
|
||||||
//调用下面的getDocument方法,获取该文件的document
|
|
||||||
Document doc = getDocument(file);
|
|
||||||
//添加索引文档
|
|
||||||
//Document doc = json2Doc(jsonDoc);
|
|
||||||
// Document doc = new Document();
|
|
||||||
Field fieldContent = new TextField("fieldContent", FileUtils.readFileToString(null, "UTF-8"), Field.Store.YES);
|
|
||||||
|
|
||||||
//将doc添加到索引中
|
|
||||||
writer.addDocument(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文档,文档里再设置每个字段,就类似于数据库中的一行记录
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private Document getDocument(File file) throws Exception {
|
|
||||||
Document doc = new Document();
|
|
||||||
//开始添加字段
|
|
||||||
//添加内容
|
|
||||||
doc.add(new TextField("contents", new FileReader(file)));
|
|
||||||
//添加文件名,并把这个字段存到索引文件里
|
|
||||||
doc.add(new TextField("fileName", file.getName(), Field.Store.YES));
|
|
||||||
//添加文件路径
|
|
||||||
doc.add(new TextField("fullPath", file.getCanonicalPath(), Field.Store.YES));
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Document json2Doc(String strDoc) {
|
|
||||||
Document doc = new Document();
|
|
||||||
JSONObject jsonDoc = JSONObject.parseObject(strDoc);
|
|
||||||
Set<String> keys = jsonDoc.keySet();
|
|
||||||
for (String key : keys) {
|
|
||||||
doc.add(new TextField(key, jsonDoc.getString(key), Field.Store.YES));
|
|
||||||
}
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLogIndex(String msg) throws IOException {
|
|
||||||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
|
||||||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
|
||||||
//步骤二:创建一个IndexWriter对象,用于写索引
|
|
||||||
// Analyzer analyzer = new StandardAnalyzer();
|
|
||||||
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new IKAnalyzer(false)));
|
|
||||||
// indexWriter.deleteAll();//清理所有索引库
|
|
||||||
// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
|
||||||
//记录索引开始时间
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
|
||||||
Document document = new Document();
|
|
||||||
document.add(new TextField("fieldContent", msg, Field.Store.YES));
|
|
||||||
indexWriter.addDocument(document);
|
|
||||||
//记录索引结束时间
|
|
||||||
long endTime = System.currentTimeMillis();
|
|
||||||
System.out.println("建立索引" + "共耗时" + (endTime - startTime) + "毫秒");
|
|
||||||
indexWriter.commit();
|
|
||||||
//步骤八:关闭资源
|
|
||||||
indexWriter.close();
|
|
||||||
System.out.println("建立索引成功-----关闭资源");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统的日志文件路径
|
|
||||||
*/
|
|
||||||
@Value("${logging.file.path}")
|
|
||||||
private String logUrl;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
|
||||||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
|
||||||
//步骤二:创建一个IndexWriter对象,用于写索引
|
|
||||||
// Analyzer analyzer = new StandardAnalyzer();
|
|
||||||
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new IKAnalyzer(false)));
|
|
||||||
|
|
||||||
indexWriter.deleteAll();//清理所有索引库
|
|
||||||
// indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
|
||||||
//记录索引开始时间
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
|
||||||
File file = new File("D:\\testlog");
|
|
||||||
//步骤四:获取文件列表
|
|
||||||
File[] files = file.listFiles();
|
|
||||||
for (File item : files) {
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(item));
|
|
||||||
String strLine = null;
|
|
||||||
while (null != (strLine = bufferedReader.readLine())) {
|
|
||||||
Document document = new Document();
|
|
||||||
document.add(new TextField("fieldContent", strLine, Field.Store.YES));
|
|
||||||
indexWriter.addDocument(document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//记录索引结束时间
|
|
||||||
long endTime = System.currentTimeMillis();
|
|
||||||
System.out.println("建立索引" + "共耗时" + (endTime - startTime) + "毫秒");
|
|
||||||
indexWriter.commit();
|
|
||||||
//步骤八:关闭资源
|
|
||||||
indexWriter.close();
|
|
||||||
System.out.println("建立索引成功-----关闭资源");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,9 @@ import org.apache.lucene.index.IndexWriter;
|
|||||||
import org.apache.lucene.index.IndexWriterConfig;
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.FSDirectory;
|
import org.apache.lucene.store.FSDirectory;
|
||||||
import org.nl.common.utils.YmlConfigFileUtil;
|
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 org.wltea.analyzer.lucene.IKAnalyzer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,7 +32,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
||||||
|
|
||||||
private Directory index;
|
private static Directory index;
|
||||||
public static IndexWriter indexWriter;
|
public static IndexWriter indexWriter;
|
||||||
|
|
||||||
|
|
||||||
@@ -38,24 +40,25 @@ public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
|||||||
public void start() {
|
public void start() {
|
||||||
super.start();
|
super.start();
|
||||||
try {
|
try {
|
||||||
// 读取配置文件
|
init();
|
||||||
Properties properties = YmlConfigFileUtil.readConfig("config/application.yml");
|
} catch (Exception e) {
|
||||||
|
|
||||||
// 获取配置值
|
|
||||||
String luceneDir = properties.getProperty("lucene.index.path");
|
|
||||||
index = FSDirectory.open(Paths.get(luceneDir));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
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 索引
|
// 初始化 Lucene 索引
|
||||||
Analyzer analyzer = new IKAnalyzer();
|
Analyzer analyzer = new IKAnalyzer();
|
||||||
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||||
try {
|
indexWriter = new IndexWriter(index, config);
|
||||||
indexWriter = new IndexWriter(index, config);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
package org.nl.config.lucene;
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
|
||||||
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.wltea.analyzer.lucene.IKAnalyzer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 、
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author generator
|
|
||||||
* @since 2023-11-16
|
|
||||||
*/
|
|
||||||
public class LuceneIndexWriter {
|
|
||||||
private static IndexWriter indexWriter;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath());
|
|
||||||
IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer());
|
|
||||||
indexWriter = new IndexWriter(directory, config);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
/**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
||||||
try {
|
|
||||||
closeIndexWriter();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
/**在线程结束时,自动关闭IndexWriter*/
|
|
||||||
public static IndexWriter getIndexWriter() {
|
|
||||||
return indexWriter;
|
|
||||||
}
|
|
||||||
/**关闭IndexWriter
|
|
||||||
* @throws IOException
|
|
||||||
* @throws CorruptIndexException */
|
|
||||||
public static void closeIndexWriter() throws Exception {
|
|
||||||
if(indexWriter != null) {
|
|
||||||
indexWriter.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
indexWriter.deleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDate(String timeString) throws ParseException {
|
|
||||||
//时间格式
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
|
||||||
Date date = sdf.parse(timeString);
|
|
||||||
//格式化后的时间
|
|
||||||
timeString = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss.SSS");
|
|
||||||
return timeString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -95,6 +95,7 @@ public class Searcher {
|
|||||||
whereJson.get(LogMessageConstant.FIELD_LEVEL).toString()));
|
whereJson.get(LogMessageConstant.FIELD_LEVEL).toString()));
|
||||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||||
}
|
}
|
||||||
|
// 使用实体接收
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
TopFieldCollector collector = TopFieldCollector.create(sort, 20000, 0);
|
TopFieldCollector collector = TopFieldCollector.create(sort, 20000, 0);
|
||||||
searcher.search(booleanQueryBuilder.build(), collector);
|
searcher.search(booleanQueryBuilder.build(), collector);
|
||||||
|
|||||||
@@ -1,48 +1,48 @@
|
|||||||
package org.nl.system.service.lucene;
|
//package org.nl.system.service.lucene;
|
||||||
|
//
|
||||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
//import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||||
|
//
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* <p>
|
// * <p>
|
||||||
* 日志检索服务
|
// * 日志检索服务
|
||||||
* </p>
|
// * </p>
|
||||||
*
|
// *
|
||||||
* @author generator
|
// * @author generator
|
||||||
* @since 2023-11-16
|
// * @since 2023-11-16
|
||||||
*/
|
// */
|
||||||
public interface LuceneExecuteLogService {
|
//public interface LuceneExecuteLogService {
|
||||||
/**
|
// /**
|
||||||
* 设备光电变化实时光电信号
|
// * 设备光电变化实时光电信号
|
||||||
*
|
// *
|
||||||
* @param device_code 设备编号
|
// * @param device_code 设备编号
|
||||||
* @param key plc信号
|
// * @param key plc信号
|
||||||
* @param value plc信号值
|
// * @param value plc信号值
|
||||||
*/
|
// */
|
||||||
void deviceItemValue(String device_code, String key, String value);
|
// void deviceItemValue(String device_code, String key, String value);
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 设备执行日志,会保留历史记录
|
// * 设备执行日志,会保留历史记录
|
||||||
*
|
// *
|
||||||
* @param luceneLogDto 日志结果对象
|
// * @param luceneLogDto 日志结果对象
|
||||||
*/
|
// */
|
||||||
void deviceExecuteLog(LuceneLogDto luceneLogDto);
|
// void deviceExecuteLog(LuceneLogDto luceneLogDto);
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 接口日志,会保留历史记录
|
// * 接口日志,会保留历史记录
|
||||||
* @param luceneLogDto 日志结果对象
|
// * @param luceneLogDto 日志结果对象
|
||||||
* @throws IOException
|
// * @throws IOException
|
||||||
*/
|
// */
|
||||||
void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException;
|
// void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 设备执行日志,会保留历史记录
|
// * 设备执行日志,会保留历史记录
|
||||||
*
|
// *
|
||||||
* @param name 日志名称
|
// * @param name 日志名称
|
||||||
* @param message 日志信息
|
// * @param message 日志信息
|
||||||
*/
|
// */
|
||||||
void extLog(String name, String message);
|
// void extLog(String name, String message);
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -1,111 +1,111 @@
|
|||||||
package org.nl.system.service.lucene.impl;
|
//package org.nl.system.service.lucene.impl;
|
||||||
|
//
|
||||||
import cn.hutool.core.date.DateTime;
|
//import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
//import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
//import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
//import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
//import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.lucene.document.Document;
|
//import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
//import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.StringField;
|
//import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
//import org.apache.lucene.index.IndexWriter;
|
||||||
import org.nl.common.enums.LogTypeEnum;
|
//import org.nl.common.enums.LogTypeEnum;
|
||||||
import org.nl.config.lucene.DynamicLogger;
|
//import org.nl.config.lucene.DynamicLogger;
|
||||||
import org.nl.config.lucene.LuceneIndexWriter;
|
//import org.nl.config.lucene.LuceneIndexWriter;
|
||||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
//import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
//import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||||
import org.slf4j.Logger;
|
//import org.slf4j.Logger;
|
||||||
import org.slf4j.MDC;
|
//import org.slf4j.MDC;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
//import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
//import org.springframework.stereotype.Service;
|
||||||
|
//
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author jlm
|
// * @author jlm
|
||||||
* @description 服务实现
|
// * @description 服务实现
|
||||||
* @date 2023-04-11
|
// * @date 2023-04-11
|
||||||
*/
|
// */
|
||||||
@Service
|
//@Service
|
||||||
@RequiredArgsConstructor
|
//@RequiredArgsConstructor
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
//public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 日志目录
|
// * 日志目录
|
||||||
*/
|
// */
|
||||||
@Value("${logging.file.path}")
|
// @Value("${logging.file.path}")
|
||||||
private String logPath;
|
// private String logPath;
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void deviceItemValue(String device_code, String key, String value) {
|
// public void deviceItemValue(String device_code, String key, String value) {
|
||||||
String now = DateUtil.now();
|
// String now = DateUtil.now();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SneakyThrows
|
// @SneakyThrows
|
||||||
@Override
|
// @Override
|
||||||
public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
|
// public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
|
||||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
// luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||||
addIndex(luceneLogDto);
|
// addIndex(luceneLogDto);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException {
|
// public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException {
|
||||||
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
|
// luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
|
||||||
addIndex(luceneLogDto);
|
// addIndex(luceneLogDto);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void addIndex(LuceneLogDto luceneLogDto) throws IOException {
|
// private void addIndex(LuceneLogDto luceneLogDto) throws IOException {
|
||||||
IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
// IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
||||||
//创建一个Document对象
|
// //创建一个Document对象
|
||||||
Document document = new Document();
|
// Document document = new Document();
|
||||||
try {
|
// try {
|
||||||
//记录索引开始时间
|
// //记录索引开始时间
|
||||||
long startTime = System.currentTimeMillis();
|
// long startTime = System.currentTimeMillis();
|
||||||
//向document对象中添加域。
|
// //向document对象中添加域。
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) {
|
||||||
document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
// document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) {
|
||||||
document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES));
|
// document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) {
|
||||||
document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES));
|
// document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) {
|
||||||
document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES));
|
// document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) {
|
||||||
document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES));
|
// document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) {
|
// if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) {
|
||||||
document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES));
|
// document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES));
|
||||||
}
|
// }
|
||||||
document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES));
|
// document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES));
|
||||||
document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES));
|
// document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES));
|
||||||
indexWriter.addDocument(document);
|
// indexWriter.addDocument(document);
|
||||||
//记录索引结束时间
|
// //记录索引结束时间
|
||||||
long endTime = System.currentTimeMillis();
|
// long endTime = System.currentTimeMillis();
|
||||||
indexWriter.commit();
|
// indexWriter.commit();
|
||||||
//实现日志文件按业务独立生成日志文件到指定路径
|
// //实现日志文件按业务独立生成日志文件到指定路径
|
||||||
DynamicLogger loggerBuilder =new DynamicLogger(logPath+"\\"+luceneLogDto.getLogType()+"\\");
|
// DynamicLogger loggerBuilder =new DynamicLogger(logPath+"\\"+luceneLogDto.getLogType()+"\\");
|
||||||
Logger logger = loggerBuilder.getLogger(luceneLogDto.getDevice_code());
|
// Logger logger = loggerBuilder.getLogger(luceneLogDto.getDevice_code());
|
||||||
logger.info("{}",luceneLogDto.toString());
|
// logger.info("{}",luceneLogDto.toString());
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
// log.error(e.getMessage(), e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void extLog(String name, String message) {
|
// public void extLog(String name, String message) {
|
||||||
try {
|
// try {
|
||||||
MDC.put(name, name);
|
// MDC.put(name, name);
|
||||||
log.info("{}", message);
|
// log.info("{}", message);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
} finally {
|
// } finally {
|
||||||
MDC.remove(name);
|
// MDC.remove(name);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.nl.config.IdUtil;
|
|||||||
import org.nl.config.language.LangProcess;
|
import org.nl.config.language.LangProcess;
|
||||||
import org.nl.system.service.dict.dao.Dict;
|
import org.nl.system.service.dict.dao.Dict;
|
||||||
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
|
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
|
||||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
|
||||||
import org.nl.system.service.menu.dto.MenuDto;
|
import org.nl.system.service.menu.dto.MenuDto;
|
||||||
import org.nl.system.service.menu.ISysMenuService;
|
import org.nl.system.service.menu.ISysMenuService;
|
||||||
import org.nl.system.service.menu.dao.SysMenu;
|
import org.nl.system.service.menu.dao.SysMenu;
|
||||||
@@ -54,9 +53,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysDictMapper sysDictMapper;
|
private SysDictMapper sysDictMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LuceneExecuteLogService luceneExecuteLogService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuDto> queryAll(Map<String, Object> param) {
|
public List<MenuDto> queryAll(Map<String, Object> param) {
|
||||||
// 父节点标识
|
// 父节点标识
|
||||||
|
|||||||
@@ -14,23 +14,5 @@ nl:
|
|||||||
port: 6379
|
port: 6379
|
||||||
password: null
|
password: null
|
||||||
database: 1
|
database: 1
|
||||||
oracle:
|
|
||||||
ip: 172.27.37.66
|
|
||||||
port: 1521
|
|
||||||
scheme: RTMES
|
|
||||||
username: LMSTELCOM
|
|
||||||
password: LMSTELCOM_6463
|
|
||||||
sqlserver:
|
|
||||||
ip: 10.93.41.2
|
|
||||||
port: WINCC
|
|
||||||
username: sa
|
|
||||||
password: 123
|
|
||||||
database: 马钢_RH
|
|
||||||
dm:
|
|
||||||
ip: localhost
|
|
||||||
port: 5236
|
|
||||||
scheme: NLADMIN
|
|
||||||
username: NLADMIN
|
|
||||||
password: 123456789
|
|
||||||
logging-path: C:\log\wms
|
logging-path: C:\log\wms
|
||||||
dynamic-log-path: C:\log\lms
|
dynamic-log-path: C:\log\lms
|
||||||
|
|||||||
@@ -14,17 +14,5 @@ nl:
|
|||||||
port: 6379
|
port: 6379
|
||||||
password: null
|
password: null
|
||||||
database: 1
|
database: 1
|
||||||
oracle:
|
|
||||||
ip: 172.27.37.66
|
|
||||||
port: 1521
|
|
||||||
scheme: RTMES
|
|
||||||
username: LMSTELCOM
|
|
||||||
password: LMSTELCOM_6463
|
|
||||||
sqlserver:
|
|
||||||
ip: 10.93.41.2
|
|
||||||
port: WINCC
|
|
||||||
username: sa
|
|
||||||
password: 123
|
|
||||||
database: 马钢_RH
|
|
||||||
logging-path: C:\log\wms
|
logging-path: C:\log\wms
|
||||||
dynamic-log-path: C:\log\lms
|
dynamic-log-path: C:\log\lms
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ server:
|
|||||||
relaxed-path-chars: [ '|','{','}','[',']' ] #字符问题: https://blog.csdn.net/weixin_41996632/article/details/90715118
|
relaxed-path-chars: [ '|','{','}','[',']' ] #字符问题: https://blog.csdn.net/weixin_41996632/article/details/90715118
|
||||||
lucene:
|
lucene:
|
||||||
index:
|
index:
|
||||||
path: D:\lucene\index
|
path: D:\lucene2\index
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: dev
|
||||||
@@ -61,24 +61,6 @@ spring:
|
|||||||
username: ${DB_USER:${nl.config.mysql.username}}
|
username: ${DB_USER:${nl.config.mysql.username}}
|
||||||
password: ${DB_PWD:${nl.config.mysql.password}}
|
password: ${DB_PWD:${nl.config.mysql.password}}
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
oracle:
|
|
||||||
driver-class-name: oracle.jdbc.OracleDriver
|
|
||||||
url: jdbc:oracle:thin:@${nl.config.oracle.ip}:${nl.config.oracle.port}:${nl.config.oracle.scheme}
|
|
||||||
username: ${DB_USER:${nl.config.oracle.username}}
|
|
||||||
password: ${DB_PWD:${nl.config.oracle.password}}
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
sqlserver:
|
|
||||||
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
|
||||||
url: jdbc:sqlserver://${nl.config.sqlserver.ip}\${nl.config.sqlserver.port};DatabaseName=${nl.config.sqlserver.database}
|
|
||||||
username: ${DB_USER:${nl.config.sqlserver.username}}
|
|
||||||
password: ${DB_PWD:${nl.config.sqlserver.password}}
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
dm:
|
|
||||||
driver-class-name: dm.jdbc.driver.DmDriver
|
|
||||||
url: jdbc:dm://${nl.config.dm.ip}:${nl.config.dm.port}/${nl.config.dm.scheme}?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
|
|
||||||
username: ${nl.config.dm.username}
|
|
||||||
password: ${nl.config.dm.password}
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
druid:
|
druid:
|
||||||
filters:
|
filters:
|
||||||
DruidFilter,stat
|
DruidFilter,stat
|
||||||
@@ -86,18 +68,6 @@ spring:
|
|||||||
min-idle: 15 #最小连接池数量
|
min-idle: 15 #最小连接池数量
|
||||||
maxActive: 30 #最大连接池数量
|
maxActive: 30 #最大连接池数量
|
||||||
maxWait: 3000 #获取连接时最大等待时间,单位毫秒
|
maxWait: 3000 #获取连接时最大等待时间,单位毫秒
|
||||||
#申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
|
|
||||||
test-while-idle: true
|
|
||||||
time-between-eviction-runs-millis: 300000 #既作为检测的间隔时间又作为test-while-idle执行的依据
|
|
||||||
min-evictable-idle-time-millis: 900000 #销毁线程时检测当前连接的最后活动时间和当前时间差大于该值时,关闭当前连接
|
|
||||||
#用来检测连接是否有效的sql
|
|
||||||
#mysql中为 select 'x'
|
|
||||||
#oracle中为 select 1 from dual
|
|
||||||
validation-query: SELECT 'x'
|
|
||||||
test-on-borrow: true #申请连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为true
|
|
||||||
test-on-return: false #归还连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为true
|
|
||||||
pool-prepared-statements: true #是否缓存preparedStatement,mysql5.5+建议开启
|
|
||||||
max-pool-prepared-statement-per-connection-size: 20 #当值大于20时poolPreparedStatements会自动修改为true
|
|
||||||
flyway:
|
flyway:
|
||||||
#开启
|
#开启
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@@ -49,8 +49,21 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
|
|
||||||
</appender>
|
</appender>
|
||||||
<appender name="luceneAppender" class="org.nl.config.lucene.LuceneAppender" >
|
<appender name="luceneAppender" class="org.nl.config.lucene.LuceneAppender" >
|
||||||
|
<!-- Filter for INFO level -->
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
<level>DEBUG</level>
|
<level>INFO</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>NEXT</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<!-- Filter for WARN level -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>WARN</level>
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<onMismatch>NEXT</onMismatch>
|
||||||
|
</filter>
|
||||||
|
<!-- Filter for ERROR level -->
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<level>ERROR</level>
|
||||||
<onMatch>ACCEPT</onMatch>
|
<onMatch>ACCEPT</onMatch>
|
||||||
<onMismatch>DENY</onMismatch>
|
<onMismatch>DENY</onMismatch>
|
||||||
</filter>
|
</filter>
|
||||||
|
|||||||
Reference in New Issue
Block a user