21 changed files with 158 additions and 414 deletions
@ -0,0 +1,34 @@ |
|||
package org.nl.modules.lucene.common; |
|||
/** |
|||
* @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.context.AspectLogContext; |
|||
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 = AspectLogContext.getLogValue(); |
|||
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); |
|||
} |
|||
|
|||
} |
@ -1,65 +0,0 @@ |
|||
package org.nl.modules.lucene.common; |
|||
|
|||
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.nl.modules.lucene.config.UrlConfig; |
|||
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; |
|||
|
|||
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(){
|
|||
// @Override
|
|||
// public void run() {
|
|||
// 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; |
|||
} |
|||
|
|||
} |
@ -1,41 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<included> |
|||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/> |
|||
<property name="LOG_HOME" value="${logPath}"/> |
|||
<define name="DEVICECODE" class="org.nl.modules.logging.DeviceCodeDir"/> |
|||
<!-- 按照每天生成日志文件 --> |
|||
<appender name="FILE_LUCENE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
|||
<!--日志文件输出的文件名--> |
|||
<FileNamePattern>${LOG_HOME}/lucene/${DEVICECODE}/%d{yyyy-MM-dd}.%i.log</FileNamePattern> |
|||
<!--日志文件保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
<!--单个日志最大容量 至少10MB才能看得出来--> |
|||
<maxFileSize>200MB</maxFileSize> |
|||
<!--所有日志最多占多大容量--> |
|||
<totalSizeCap>2GB</totalSizeCap> |
|||
</rollingPolicy> |
|||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
|||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>${log.charset}</charset> |
|||
</encoder> |
|||
|
|||
</appender> |
|||
|
|||
<appender name="luceneAppender" class="org.nl.modules.lucene.common.LuceneAppender" /> |
|||
<appender name="asyncLuceneAppender" class="ch.qos.logback.classic.AsyncAppender"> |
|||
<appender-ref ref="luceneAppender" /> |
|||
<!-- 设置队列大小,根据您的需求调整 --> |
|||
<queueSize>512</queueSize> |
|||
</appender> |
|||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false"> |
|||
<appender-ref ref="FILE3"/> |
|||
</logger>--> |
|||
|
|||
<!-- 打印sql --> |
|||
<logger name="org.nl.modules.lucene.service.impl.LuceneExecuteLogServiceImpl" level="info" additivity="true"> |
|||
<appender-ref ref="FILE_LUCENE"/> |
|||
<appender-ref ref="asyncLuceneAppender"/> |
|||
</logger> |
|||
</included> |
Loading…
Reference in new issue