增加日志管理
This commit is contained in:
parent
31af39258d
commit
548aeadf6e
|
|
@ -66,6 +66,6 @@ JetLinks 是一个物联网基础平台,用于快速建立物联网相关业务
|
|||
| 线下技术支持 | ⭕ | ⭕ | ✅ |
|
||||
| 定制开发 | ⭕ | ⭕ | ✅ |
|
||||
| 商业限制 | 无 | 单个项目 | 无 |
|
||||
| 定价 | 免费 | 孵化中待定 | 孵化中待定 |
|
||||
| 定价 | 免费 | 联系我们 | 联系我们 |
|
||||
|
||||
⚠️:所有版本均不可发布为与JetLinks同类的产品进行二次销售.
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>jetlinks-components</artifactId>
|
||||
<groupId>org.jetlinks.community</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>logging-component</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-access-logging-aop</artifactId>
|
||||
<version>${hsweb.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetlinks.community</groupId>
|
||||
<artifactId>elasticsearch-component</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.jetlinks.community.logging.access;
|
||||
|
||||
import org.hswebframework.web.logging.events.AccessLoggerAfterEvent;
|
||||
import org.jetlinks.community.logging.configuration.LoggingProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AccessLoggingTranslator {
|
||||
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private final LoggingProperties properties;
|
||||
|
||||
public AccessLoggingTranslator(ApplicationEventPublisher eventPublisher, LoggingProperties properties) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void translate(AccessLoggerAfterEvent event) {
|
||||
eventPublisher.publishEvent(SerializableAccessLog.of(event.getLogger()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package org.jetlinks.community.logging.access;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hswebframework.utils.StringUtils;
|
||||
import org.hswebframework.web.bean.FastBeanCopier;
|
||||
import org.hswebframework.web.logging.AccessLogger;
|
||||
import org.hswebframework.web.logging.AccessLoggerInfo;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @see org.hswebframework.web.logging.AccessLoggerInfo
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class SerializableAccessLog implements Serializable {
|
||||
|
||||
/**
|
||||
* 日志id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 访问的操作
|
||||
*
|
||||
* @see AccessLogger#value()
|
||||
*/
|
||||
private String action;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*
|
||||
* @see AccessLogger#describe()
|
||||
*/
|
||||
private String describe;
|
||||
|
||||
/**
|
||||
* 访问对应的java方法
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 访问对应的java类
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 请求的参数,参数为java方法的参数而不是http参数,key为参数名,value为参数值.
|
||||
*/
|
||||
private Map<String, Object> parameters;
|
||||
|
||||
/**
|
||||
* 请求者ip地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 请求的url地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* http 请求头集合
|
||||
*/
|
||||
private Map<String, String> httpHeaders = new HashMap<>();
|
||||
|
||||
private Map<String, String> context = new HashMap<>();
|
||||
|
||||
/**
|
||||
* http 请求方法, GET,POST...
|
||||
*/
|
||||
private String httpMethod;
|
||||
|
||||
/**
|
||||
* 响应结果,方法的返回值
|
||||
*/
|
||||
//private Object response;
|
||||
|
||||
/**
|
||||
* 请求时间戳
|
||||
*
|
||||
* @see System#currentTimeMillis()
|
||||
*/
|
||||
private long requestTime;
|
||||
|
||||
/**
|
||||
* 响应时间戳
|
||||
*
|
||||
* @see System#currentTimeMillis()
|
||||
*/
|
||||
private long responseTime;
|
||||
|
||||
/**
|
||||
* 异常信息,请求对应方法抛出的异常
|
||||
*/
|
||||
private String exception;
|
||||
|
||||
public static SerializableAccessLog of(AccessLoggerInfo info) {
|
||||
SerializableAccessLog accessLog = FastBeanCopier.copy(info, new SerializableAccessLog(), "parameters", "method", "target", "exception");
|
||||
accessLog.setMethod(info.getMethod().getName());
|
||||
accessLog.setTarget(info.getTarget().getName());
|
||||
accessLog.setException(info.getException() == null ? ""
|
||||
: StringUtils.throwable2String(info.getException()));
|
||||
Map<String, Object> newParameter = info.getParameters()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> {
|
||||
Object value = e.getValue();
|
||||
if (value instanceof FilePart) {
|
||||
return ("file:") + ((FilePart) value).filename();
|
||||
}
|
||||
return JSON.toJSONString(value);
|
||||
}));
|
||||
|
||||
accessLog.setParameters(newParameter);
|
||||
return accessLog;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.jetlinks.community.logging.configuration;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldDateFormat;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldType;
|
||||
import org.jetlinks.community.elastic.search.index.CreateIndex;
|
||||
import org.jetlinks.community.elastic.search.service.IndexOperationService;
|
||||
import org.jetlinks.community.logging.event.handler.LoggerIndexProvider;
|
||||
import org.jetlinks.community.logging.logback.SystemLoggingAppender;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(LoggingProperties.class)
|
||||
@Slf4j
|
||||
public class LoggingConfiguration implements ApplicationEventPublisherAware {
|
||||
|
||||
|
||||
private final LoggingProperties properties;
|
||||
|
||||
public LoggingConfiguration(LoggingProperties properties) {
|
||||
this.properties = properties;
|
||||
SystemLoggingAppender.staticContext.putAll(properties.getSystem().getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
SystemLoggingAppender.publisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.jetlinks.community.logging.configuration;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ConfigurationProperties(prefix = "jetlinks.logging")
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoggingProperties {
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
* @see lombok.extern.slf4j.Slf4j
|
||||
* @see org.slf4j.Logger
|
||||
* @see org.jetlinks.community.logging.logback.SystemLoggingAppender
|
||||
* @see SerializableSystemLog
|
||||
* @see org.jetlinks.community.logging.event.SystemLoggingEvent
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private SystemLoggingProperties system = new SystemLoggingProperties();
|
||||
|
||||
/**
|
||||
* 访问日志
|
||||
*
|
||||
* @see org.hswebframework.web.logging.AccessLogger
|
||||
* @see org.hswebframework.web.loggin.aop.EnableAccessLogger
|
||||
* @see org.jetlinks.community.logging.event.AccessLoggingEvent
|
||||
* @see org.jetlinks.community.logging.access.SerializableAccessLog
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
private AccessLoggingProperties access = new AccessLoggingProperties();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class SystemLoggingProperties {
|
||||
/**
|
||||
* 系统日志上下文,通常用于在日志中标识当前服务等
|
||||
*
|
||||
* @see org.hswebframework.web.logger.ReactiveLogger#mdc(String, String)
|
||||
* @see org.slf4j.MDC
|
||||
*/
|
||||
private Map<String, String> context = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class AccessLoggingProperties {
|
||||
//指定按path过滤日志
|
||||
private List<String> pathExcludes = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.jetlinks.community.logging.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetlinks.community.logging.access.SerializableAccessLog;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class AccessLoggingEvent {
|
||||
SerializableAccessLog log;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.jetlinks.community.logging.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class SystemLoggingEvent {
|
||||
SerializableSystemLog log;
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package org.jetlinks.community.logging.event.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldDateFormat;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldType;
|
||||
import org.jetlinks.community.elastic.search.index.CreateIndex;
|
||||
import org.jetlinks.community.elastic.search.service.ElasticSearchService;
|
||||
import org.jetlinks.community.elastic.search.service.IndexOperationService;
|
||||
import org.jetlinks.community.logging.access.SerializableAccessLog;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author bsetfeng
|
||||
* @since 1.0
|
||||
**/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Order(5)
|
||||
public class AccessLoggerEventHandler {
|
||||
|
||||
private final ElasticSearchService elasticSearchService;
|
||||
|
||||
public AccessLoggerEventHandler(ElasticSearchService elasticSearchService, IndexOperationService indexOperationService) {
|
||||
this.elasticSearchService = elasticSearchService;
|
||||
CreateIndexRequest accessLoggerIndex = CreateIndex.createInstance()
|
||||
.addIndex(LoggerIndexProvider.ACCESS.getStandardIndex())
|
||||
.createMapping()
|
||||
.addFieldName("requestTime").addFieldType(FieldType.DATE).addFieldDateFormat(FieldDateFormat.epoch_millis, FieldDateFormat.simple_date, FieldDateFormat.strict_date_time).commit()
|
||||
.addFieldName("responseTime").addFieldType(FieldType.DATE).addFieldDateFormat(FieldDateFormat.epoch_millis, FieldDateFormat.simple_date, FieldDateFormat.strict_date_time).commit()
|
||||
.addFieldName("action").addFieldType(FieldType.KEYWORD).commit()
|
||||
.addFieldName("ip").addFieldType(FieldType.KEYWORD).commit()
|
||||
.addFieldName("url").addFieldType(FieldType.KEYWORD).commit()
|
||||
.addFieldName("httpHeaders").addFieldType(FieldType.OBJECT).commit()
|
||||
.addFieldName("context").addFieldType(FieldType.OBJECT).commit()
|
||||
.end()
|
||||
.createIndexRequest();
|
||||
indexOperationService.init(accessLoggerIndex)
|
||||
.doOnError(err -> log.error(err.getMessage(), err))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
|
||||
@EventListener
|
||||
public void acceptAccessLoggerInfo(SerializableAccessLog info) {
|
||||
elasticSearchService.commit(LoggerIndexProvider.ACCESS, Mono.just(info)).subscribe();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package org.jetlinks.community.logging.event.handler;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.jetlinks.community.elastic.search.index.ElasticIndex;
|
||||
|
||||
/**
|
||||
* @author bsetfeng
|
||||
* @since 1.0
|
||||
**/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum LoggerIndexProvider implements ElasticIndex {
|
||||
|
||||
ACCESS("access_log", "_doc"),
|
||||
SYSTEM("system_log", "_doc");
|
||||
|
||||
private String index;
|
||||
|
||||
private String type;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.jetlinks.community.logging.event.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldDateFormat;
|
||||
import org.jetlinks.community.elastic.search.enums.FieldType;
|
||||
import org.jetlinks.community.elastic.search.index.CreateIndex;
|
||||
import org.jetlinks.community.elastic.search.service.ElasticSearchService;
|
||||
import org.jetlinks.community.elastic.search.service.IndexOperationService;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author bsetfeng
|
||||
* @since 1.0
|
||||
**/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Order(5)
|
||||
public class SystemLoggerEventHandler {
|
||||
|
||||
|
||||
private final ElasticSearchService elasticSearchService;
|
||||
|
||||
public SystemLoggerEventHandler(ElasticSearchService elasticSearchService, IndexOperationService indexOperationService) {
|
||||
this.elasticSearchService = elasticSearchService;
|
||||
|
||||
CreateIndexRequest systemLoggerIndex = CreateIndex.createInstance()
|
||||
.addIndex(LoggerIndexProvider.SYSTEM.getStandardIndex())
|
||||
.createMapping()
|
||||
.addFieldName("createTime").addFieldType(FieldType.DATE).addFieldDateFormat(FieldDateFormat.epoch_millis, FieldDateFormat.simple_date, FieldDateFormat.strict_date_time).commit()
|
||||
.addFieldName("name").addFieldType(FieldType.KEYWORD).commit()
|
||||
.addFieldName("level").addFieldType(FieldType.KEYWORD).commit()
|
||||
.addFieldName("message").addFieldType(FieldType.KEYWORD).commit()
|
||||
.end()
|
||||
.createIndexRequest();
|
||||
|
||||
indexOperationService.init(systemLoggerIndex)
|
||||
.doOnError(err -> log.error(err.getMessage(), err))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void acceptAccessLoggerInfo(SerializableSystemLog info) {
|
||||
elasticSearchService.commit(LoggerIndexProvider.SYSTEM, Mono.just(info))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package org.jetlinks.community.logging.logback;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.spi.IThrowableProxy;
|
||||
import ch.qos.logback.classic.spi.StackTraceElementProxy;
|
||||
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
|
||||
import ch.qos.logback.core.CoreConstants;
|
||||
import ch.qos.logback.core.UnsynchronizedAppenderBase;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.id.IDGenerator;
|
||||
import org.hswebframework.web.utils.ModuleUtils;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class SystemLoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
|
||||
|
||||
public static ApplicationEventPublisher publisher;
|
||||
|
||||
public static final Map<String, String> staticContext = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent event) {
|
||||
|
||||
if (publisher == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
StackTraceElement element = event.getCallerData()[0];
|
||||
IThrowableProxy proxies = event.getThrowableProxy();
|
||||
String message = event.getFormattedMessage();
|
||||
String stack = null;
|
||||
if (null != proxies) {
|
||||
int commonFrames = proxies.getCommonFrames();
|
||||
StackTraceElementProxy[] stepArray = proxies.getStackTraceElementProxyArray();
|
||||
StringJoiner joiner = new StringJoiner("\n", message + "\n[", "]");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
ThrowableProxyUtil.subjoinFirstLine(stringBuilder, proxies);
|
||||
joiner.add(stringBuilder);
|
||||
for (int i = 0; i < stepArray.length - commonFrames; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(CoreConstants.TAB);
|
||||
ThrowableProxyUtil.subjoinSTEP(sb, stepArray[i]);
|
||||
joiner.add(sb);
|
||||
}
|
||||
stack = joiner.toString();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String gitLocation = null;
|
||||
String mavenModule = null;
|
||||
try {
|
||||
Class clazz = Class.forName(element.getClassName());
|
||||
ModuleUtils.ModuleInfo moduleInfo = ModuleUtils.getModuleByClass(clazz);
|
||||
if (!StringUtils.isEmpty(moduleInfo.getGitRepository())) {
|
||||
StringBuilder javaSb = new StringBuilder();
|
||||
javaSb.append(moduleInfo.getGitLocation());
|
||||
javaSb.append("src/main/java/");
|
||||
javaSb.append((ClassUtils.getPackageName(Class.forName(element.getClassName())).replace(".", "/")));
|
||||
javaSb.append("/");
|
||||
javaSb.append(Class.forName(element.getClassName()).getSimpleName());
|
||||
javaSb.append(".java#L");
|
||||
javaSb.append(element.getLineNumber());
|
||||
gitLocation = javaSb.toString();
|
||||
}
|
||||
mavenModule = moduleInfo.getArtifactId();
|
||||
} catch (Exception e) {
|
||||
log.warn("记录系统日志时,加载类:{}错误。{}", element.getClassName(), e);
|
||||
}
|
||||
Map<String, String> context = new HashMap<>(staticContext);
|
||||
Map<String, String> mdc = MDC.getCopyOfContextMap();
|
||||
if (mdc != null) {
|
||||
context.putAll(mdc);
|
||||
}
|
||||
SerializableSystemLog info = SerializableSystemLog.builder()
|
||||
.id(IDGenerator.SNOW_FLAKE_STRING.generate())
|
||||
.mavenModule(mavenModule)
|
||||
.context(context)
|
||||
.name(event.getLoggerName())
|
||||
.level(event.getLevel().levelStr)
|
||||
.className(element.getClassName())
|
||||
.methodName(element.getMethodName())
|
||||
.lineNumber(element.getLineNumber())
|
||||
.exceptionStack(stack)
|
||||
.java(gitLocation)
|
||||
.threadName(event.getThreadName())
|
||||
.createTime(event.getTimeStamp())
|
||||
.message(message)
|
||||
.threadId(String.valueOf(Thread.currentThread().getId()))
|
||||
.build();
|
||||
try {
|
||||
publisher.publishEvent(info);
|
||||
}catch (Exception ignore){}
|
||||
} catch (Exception e) {
|
||||
log.error("组装系统日志错误", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.jetlinks.community.logging.system;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SerializableSystemLog implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
private String mavenModule;
|
||||
|
||||
private String name;
|
||||
|
||||
private String threadName;
|
||||
|
||||
private String level;
|
||||
|
||||
private String className;
|
||||
|
||||
private String methodName;
|
||||
|
||||
private int lineNumber;
|
||||
|
||||
private String java;
|
||||
|
||||
private String message;
|
||||
|
||||
private String exceptionStack;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private String threadId;
|
||||
|
||||
private Map<String, String> context;
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
<module>dashboard-component</module>
|
||||
<module>common-component</module>
|
||||
<module>notify-component</module>
|
||||
<module>logging-component</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>jetlinks-components</artifactId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
**/pom.xml.versionsBackup
|
||||
**/target/
|
||||
**/out/
|
||||
*.class
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
.idea/
|
||||
/nbproject
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.log
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
**/transaction-logs/
|
||||
!/.mvn/wrapper/maven-wrapper.jar
|
||||
/data/
|
||||
*.db
|
||||
/static/
|
||||
/upload
|
||||
/ui/upload/
|
||||
docker/data
|
||||
!ip2region.db
|
||||
!device-simulator.jar
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetlinks.community</groupId>
|
||||
<artifactId>jetlinks-manager</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>logging-manager</artifactId>
|
||||
|
||||
|
||||
<properties>
|
||||
<hsweb.framework.version>4.0.0-SNAPSHOT</hsweb.framework.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-access-logging-aop</artifactId>
|
||||
<version>${hsweb.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hswebframework.web</groupId>
|
||||
<artifactId>hsweb-starter</artifactId>
|
||||
<version>${hsweb.framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot.experimental</groupId>
|
||||
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetlinks.community</groupId>
|
||||
<artifactId>logging-component</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.r2dbc</groupId>
|
||||
<artifactId>r2dbc-h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hswebframework</groupId>
|
||||
<artifactId>hsweb-easy-orm-rdb</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.jetlinks.community.logging.controller;
|
||||
|
||||
import org.hswebframework.ezorm.core.param.QueryParam;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.authorization.annotation.QueryAction;
|
||||
import org.hswebframework.web.authorization.annotation.Resource;
|
||||
import org.jetlinks.community.logging.access.SerializableAccessLog;
|
||||
import org.jetlinks.community.logging.service.AccessLoggerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author bsetfeng
|
||||
* @since 1.0
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/logger/access")
|
||||
@Resource(id="access-logger",name = "访问日志")
|
||||
public class AccessLoggerController {
|
||||
|
||||
@Autowired
|
||||
private AccessLoggerService loggerService;
|
||||
|
||||
@GetMapping("/_query")
|
||||
@QueryAction
|
||||
public Mono<PagerResult<SerializableAccessLog>> getAccessLogger(QueryParam queryParam) {
|
||||
return loggerService.getAccessLogger(queryParam);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package org.jetlinks.community.logging.controller;
|
||||
|
||||
import org.hswebframework.ezorm.core.param.QueryParam;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.authorization.annotation.QueryAction;
|
||||
import org.hswebframework.web.authorization.annotation.Resource;
|
||||
import org.jetlinks.community.logging.service.SystemLoggerService;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author bsetfeng
|
||||
* @since 1.0
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/logger/system")
|
||||
@Resource(id="system-logger",name = "系统日志")
|
||||
public class SystemLoggerController {
|
||||
|
||||
@Autowired
|
||||
private SystemLoggerService loggerService;
|
||||
|
||||
@GetMapping("/_query")
|
||||
@QueryAction
|
||||
public Mono<PagerResult<SerializableSystemLog>> getSystemLogger(QueryParam queryParam) {
|
||||
return loggerService.getSystemLogger(queryParam);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.jetlinks.community.logging.service;
|
||||
|
||||
|
||||
import org.hswebframework.ezorm.core.param.QueryParam;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.jetlinks.community.elastic.search.service.ElasticSearchService;
|
||||
import org.jetlinks.community.logging.access.SerializableAccessLog;
|
||||
import org.jetlinks.community.logging.event.handler.LoggerIndexProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
**/
|
||||
@Service
|
||||
public class AccessLoggerService {
|
||||
|
||||
@Autowired
|
||||
private ElasticSearchService searchService;
|
||||
|
||||
public Mono<PagerResult<SerializableAccessLog>> getAccessLogger(QueryParam queryParam) {
|
||||
return searchService.queryPager(LoggerIndexProvider.ACCESS, queryParam, SerializableAccessLog.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.jetlinks.community.logging.service;
|
||||
|
||||
|
||||
import org.hswebframework.ezorm.core.param.QueryParam;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.jetlinks.community.elastic.search.service.ElasticSearchService;
|
||||
import org.jetlinks.community.logging.event.handler.LoggerIndexProvider;
|
||||
import org.jetlinks.community.logging.system.SerializableSystemLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
**/
|
||||
@Service
|
||||
public class SystemLoggerService {
|
||||
|
||||
@Autowired
|
||||
private ElasticSearchService searchService;
|
||||
|
||||
public Mono<PagerResult<SerializableSystemLog>> getSystemLogger(QueryParam queryParam) {
|
||||
return searchService.queryPager(LoggerIndexProvider.SYSTEM, queryParam, SerializableSystemLog.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
<module>device-manager</module>
|
||||
<module>network-manager</module>
|
||||
<module>notify-manager</module>
|
||||
<module>logging-manager</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
@ -129,6 +129,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>logging-manager</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetlinks</groupId>
|
||||
<artifactId>jetlinks-supports</artifactId>
|
||||
|
|
|
|||
Loading…
Reference in New Issue