This commit is contained in:
2023-02-13 13:13:23 +08:00
6 changed files with 27 additions and 10 deletions

View File

@@ -0,0 +1,18 @@
package org.nl.config;
/*
* @author ZZQ
* @Date 2023/2/13 9:58 上午
*/
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
@Data
public class ESConfig {
@Value(("${es.index}"))
private String index;
}

View File

@@ -123,11 +123,8 @@ public class LogAspect {
StackTraceElement[] stackTrace = ex.getStackTrace();
if (stackTrace!=null && stackTrace.length>0){
for (StackTraceElement stack : stackTrace) {
x++;
errorStack.append(stack.toString().replaceAll("<",">")).append("<br/>");
if (x>10){
break;
}
x++;errorStack.append(stack.toString().replaceAll("<",">")).append("<br/>");
if (x>10){ break; }
}
}
log.error("[-requestError-][请求接口:{}]【异常信息:{}】[请求参数:{}] {}", url,errorMsg,params, errorStack.append("").toString());
@@ -179,7 +176,4 @@ public class LogAspect {
return "";
}
}
}

View File

@@ -8,7 +8,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
* @author ZZQ
* @Date 2023/2/8 4:06 下午
*/
@Document(indexName = "lms_log", type = "lms_log")
@Document(indexName = "#{@ESConfig.index}", type = "lms_log")
@Data
public class LogRepositoryDTO {

View File

@@ -184,3 +184,5 @@ sa-token:
loki:
url: http://localhost:3100/loki/api/v1
systemName: lms
es:
index: lms_log

View File

@@ -186,3 +186,5 @@ sa-token:
loki:
url: http://localhost:3100/loki/api/v1
systemName: lms
es:
index: lms_log_prod

View File

@@ -15,6 +15,7 @@ https://juejin.cn/post/6844903775631572999
value="%black(%contextName-) %X{traceId} %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
<springProperty scope="context" name="lokiUrl" source="loki.url"/>
<springProperty scope="context" name="esIndex" source="es.index"/>
<springProperty scope="context" name="systemName" source="loki.systemName"/>
<property name="LOKI_URL" value="${lokiUrl}"/>
<property name="SYSTEM_NAME" value="${systemName}"/>
@@ -50,7 +51,7 @@ https://juejin.cn/post/6844903775631572999
<appender name="esLogAppender" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>http://10.1.3.90:9200/_bulk</url>
<index>lms_log</index>
<index>${esIndex}</index>
<type>lms_log</type>
<loggerName>es-logger</loggerName> <!-- optional -->
<errorLoggerName>es-error-logger</errorLoggerName> <!-- optional -->