Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
4e6b78f3
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4e6b78f3
编写于
3月 02, 2021
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:整合elk
上级
efcf4e30
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
268 addition
and
80 deletion
+268
-80
pom.xml
pom.xml
+6
-0
youlai-admin/admin-boot/pom.xml
youlai-admin/admin-boot/pom.xml
+6
-0
youlai-common/common-web/pom.xml
youlai-common/common-web/pom.xml
+5
-6
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java
...ain/java/com/youlai/common/web/aspect/LoginLogAspect.java
+0
-61
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/OptLogAspect.java
.../main/java/com/youlai/common/web/aspect/OptLogAspect.java
+25
-13
youlai-common/common-web/src/main/java/com/youlai/common/web/pojo/domain/LoginLog.java
...main/java/com/youlai/common/web/pojo/domain/LoginLog.java
+3
-0
youlai-common/common-web/src/main/java/com/youlai/common/web/pojo/domain/OptLog.java
...c/main/java/com/youlai/common/web/pojo/domain/OptLog.java
+2
-0
youlai-common/common-web/src/main/resources/logback-spring.xml
...i-common/common-web/src/main/resources/logback-spring.xml
+221
-0
未找到文件。
pom.xml
浏览文件 @
4e6b78f3
...
...
@@ -46,6 +46,7 @@
<seata.version>
1.4.1
</seata.version>
<commons-pool2-version>
2.9.0
</commons-pool2-version>
<knife4j.version>
2.0.8
</knife4j.version>
<logstash-logback-encoder.version>
6.6
</logstash-logback-encoder.version>
</properties>
<dependencies>
...
...
@@ -141,6 +142,11 @@
<version>
${knife4j.version}
</version>
</dependency>
<dependency>
<groupId>
net.logstash.logback
</groupId>
<artifactId>
logstash-logback-encoder
</artifactId>
<version>
${logstash-logback-encoder.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
youlai-admin/admin-boot/pom.xml
浏览文件 @
4e6b78f3
...
...
@@ -64,6 +64,12 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
com.youlai
</groupId>
<artifactId>
common-web
</artifactId>
<version>
${youlai.version}
</version>
</dependency>
</dependencies>
<build>
...
...
youlai-common/common-web/pom.xml
浏览文件 @
4e6b78f3
...
...
@@ -22,12 +22,6 @@
<version>
${youlai.version}
</version>
</dependency>
<dependency>
<groupId>
com.youlai
</groupId>
<artifactId>
common-redis
</artifactId>
<version>
${youlai.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
...
...
@@ -52,6 +46,11 @@
<version>
${swagger-annotations.version}
</version>
</dependency>
<dependency>
<groupId>
net.logstash.logback
</groupId>
<artifactId>
logstash-logback-encoder
</artifactId>
</dependency>
</dependencies>
</project>
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java
已删除
100644 → 0
浏览文件 @
efcf4e30
package
com.youlai.common.web.aspect
;
import
cn.hutool.json.JSONUtil
;
import
com.youlai.common.web.pojo.domain.LoginLog
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
/**
* @Author HXR
* @CreateTime 2021-03-01 16:47
*/
@Aspect
@Component
@AllArgsConstructor
@Slf4j
public
class
LoginLogAspect
{
private
RedisTemplate
redisTemplate
;
@Pointcut
(
"execution(public * com.youlai..*.controller.*.*(..))"
)
public
void
Log
()
{
}
@Around
(
"Log()"
)
public
Object
doAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
log
.
info
(
"登录日志记录"
);
long
startTime
=
System
.
nanoTime
();
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
LoginLog
loginLog
=
new
LoginLog
();
Signature
signature
=
joinPoint
.
getSignature
();
MethodSignature
methodSignature
=
(
MethodSignature
)
signature
;
Method
method
=
methodSignature
.
getMethod
();
if
(
method
.
isAnnotationPresent
(
ApiOperation
.
class
))
{
ApiOperation
apiOperation
=
method
.
getAnnotation
(
ApiOperation
.
class
);
loginLog
.
setDescription
(
apiOperation
.
value
());
}
long
endTime
=
System
.
nanoTime
();
loginLog
.
setElapsedTime
((
int
)
(
endTime
-
startTime
));
loginLog
.
setIp
(
request
.
getRemoteUser
());
loginLog
.
setUrl
(
request
.
getRequestURL
().
toString
());
loginLog
.
setMethod
(
request
.
getMethod
());
redisTemplate
.
opsForSet
().
add
(
"log:login"
,
JSONUtil
.
toJsonStr
(
loginLog
));
Object
result
=
joinPoint
.
proceed
();
return
result
;
}
}
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/OptLogAspect.java
浏览文件 @
4e6b78f3
...
...
@@ -2,22 +2,27 @@ package com.youlai.common.web.aspect;
import
cn.hutool.json.JSONUtil
;
import
com.youlai.common.web.pojo.domain.LoginLog
;
import
com.youlai.common.web.pojo.domain.OptLog
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
net.logstash.logback.marker.Markers
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @Author HXR
...
...
@@ -26,36 +31,43 @@ import java.lang.reflect.Method;
@Aspect
@Component
@AllArgsConstructor
@Slf4j
public
class
OptLogAspect
{
private
RedisTemplate
redisTemplate
;
@Pointcut
(
"execution(public * com.youlai..*.controller.*.*(..))"
)
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
OptLogAspect
.
class
);
@Pointcut
(
"execution(public * com.youlai..*.controller.*.*(..)) || execution(public * com.youlai.*.controller.*(..))"
)
public
void
Log
()
{
}
@Around
(
"Log()"
)
public
Object
doAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
log
.
info
(
"操作日志记录"
);
long
startTime
=
System
.
nanoTime
();
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
LoginLog
loginLog
=
new
Login
Log
();
OptLog
optLog
=
new
Opt
Log
();
Signature
signature
=
joinPoint
.
getSignature
();
MethodSignature
methodSignature
=
(
MethodSignature
)
signature
;
Method
method
=
methodSignature
.
getMethod
();
if
(
method
.
isAnnotationPresent
(
ApiOperation
.
class
))
{
ApiOperation
apiOperation
=
method
.
getAnnotation
(
ApiOperation
.
class
);
login
Log
.
setDescription
(
apiOperation
.
value
());
opt
Log
.
setDescription
(
apiOperation
.
value
());
}
long
endTime
=
System
.
nanoTime
();
loginLog
.
setElapsedTime
((
int
)
(
endTime
-
startTime
));
loginLog
.
setIp
(
request
.
getRemoteUser
());
loginLog
.
setUrl
(
request
.
getRequestURL
().
toString
());
loginLog
.
setMethod
(
request
.
getMethod
());
redisTemplate
.
opsForSet
().
add
(
"log:opt"
,
JSONUtil
.
toJsonStr
(
loginLog
));
optLog
.
setElapsedTime
((
int
)
(
endTime
-
startTime
));
optLog
.
setIp
(
request
.
getRemoteUser
());
optLog
.
setUrl
(
request
.
getRequestURL
().
toString
());
optLog
.
setMethod
(
request
.
getMethod
());
Object
result
=
joinPoint
.
proceed
();
optLog
.
setResult
(
result
);
Map
<
String
,
Object
>
logMap
=
new
HashMap
<>();
logMap
.
put
(
"url"
,
optLog
.
getUrl
());
logMap
.
put
(
"method"
,
optLog
.
getMethod
());
logMap
.
put
(
"elapsedTime"
,
optLog
.
getElapsedTime
());
logMap
.
put
(
"description"
,
optLog
.
getDescription
());
logMap
.
put
(
"result"
,
result
);
LOGGER
.
info
(
"123"
);
LOGGER
.
info
(
Markers
.
appendEntries
(
logMap
),
JSONUtil
.
parse
(
optLog
).
toString
());
return
result
;
}
}
youlai-common/common-web/src/main/java/com/youlai/common/web/pojo/domain/LoginLog.java
浏览文件 @
4e6b78f3
...
...
@@ -20,6 +20,9 @@ public class LoginLog {
private
String
gmtStart
;
/**
* 消耗时间
*/
private
Integer
elapsedTime
;
}
youlai-common/common-web/src/main/java/com/youlai/common/web/pojo/domain/OptLog.java
浏览文件 @
4e6b78f3
...
...
@@ -22,4 +22,6 @@ public class OptLog {
private
Integer
elapsedTime
;
private
Object
result
;
}
youlai-common/common-web/src/main/resources/logback-spring.xml
0 → 100644
浏览文件 @
4e6b78f3
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<!--引用默认日志配置-->
<include
resource=
"org/springframework/boot/logging/logback/defaults.xml"
/>
<!--使用默认的控制台日志输出实现-->
<include
resource=
"org/springframework/boot/logging/logback/console-appender.xml"
/>
<!--应用名称-->
<springProperty
scope=
"context"
name=
"APP_NAME"
source=
"spring.application.name"
defaultValue=
"springBoot"
/>
<!--日志文件保存路径-->
<property
name=
"LOG_FILE_PATH"
value=
"${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"
/>
<!--LogStash访问host-->
<springProperty
name=
"LOG_STASH_HOST"
scope=
"context"
source=
"192.168.169.186"
defaultValue=
"192.168.169.186"
/>
<!--DEBUG日志输出到文件-->
<appender
name=
"FILE_DEBUG"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--输出DEBUG以上级别日志-->
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
DEBUG
</level>
</filter>
<encoder>
<!--设置为默认的文件日志格式-->
<pattern>
${FILE_LOG_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
</encoder>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"
>
<!--设置文件命名格式-->
<fileNamePattern>
${LOG_FILE_PATH}/debug/${APP_NAME}-%d{yyyy-MM-dd}-%i.log
</fileNamePattern>
<!--设置日志文件大小,超过就重新生成文件,默认10M-->
<maxFileSize>
${LOG_FILE_MAX_SIZE:-10MB}
</maxFileSize>
<!--日志文件保留天数,默认30天-->
<maxHistory>
${LOG_FILE_MAX_HISTORY:-30}
</maxHistory>
</rollingPolicy>
</appender>
<!--ERROR日志输出到文件-->
<appender
name=
"FILE_ERROR"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--只输出ERROR级别的日志-->
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
ERROR
</level>
<onMatch>
ACCEPT
</onMatch>
<onMismatch>
DENY
</onMismatch>
</filter>
<encoder>
<!--设置为默认的文件日志格式-->
<pattern>
${FILE_LOG_PATTERN}
</pattern>
<charset>
UTF-8
</charset>
</encoder>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"
>
<!--设置文件命名格式-->
<fileNamePattern>
${LOG_FILE_PATH}/error/${APP_NAME}-%d{yyyy-MM-dd}-%i.log
</fileNamePattern>
<!--设置日志文件大小,超过就重新生成文件,默认10M-->
<maxFileSize>
${LOG_FILE_MAX_SIZE:-10MB}
</maxFileSize>
<!--日志文件保留天数,默认30天-->
<maxHistory>
${LOG_FILE_MAX_HISTORY:-30}
</maxHistory>
</rollingPolicy>
</appender>
<!--DEBUG日志输出到LogStash-->
<appender
name=
"LOG_STASH_DEBUG"
class=
"net.logstash.logback.appender.LogstashTcpSocketAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
DEBUG
</level>
</filter>
<destination>
${LOG_STASH_HOST}:5044
</destination>
<encoder
charset=
"UTF-8"
class=
"net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"
>
<providers>
<timestamp>
<timeZone>
Asia/Shanghai
</timeZone>
</timestamp>
<!--自定义日志输出格式-->
<pattern>
<pattern>
{
"project": "youlai-mall",
"level": "%level",
"service": "${APP_NAME:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger",
"message": "%message",
"stack_trace": "%exception{20}"
}
</pattern>
</pattern>
</providers>
</encoder>
<!--当有多个LogStash服务时,设置访问策略为轮询-->
<connectionStrategy>
<roundRobin>
<connectionTTL>
5 minutes
</connectionTTL>
</roundRobin>
</connectionStrategy>
</appender>
<!--ERROR日志输出到LogStash-->
<appender
name=
"LOG_STASH_ERROR"
class=
"net.logstash.logback.appender.LogstashTcpSocketAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
ERROR
</level>
<onMatch>
ACCEPT
</onMatch>
<onMismatch>
DENY
</onMismatch>
</filter>
<destination>
${LOG_STASH_HOST}:5044
</destination>
<encoder
charset=
"UTF-8"
class=
"net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"
>
<providers>
<timestamp>
<timeZone>
Asia/Shanghai
</timeZone>
</timestamp>
<!--自定义日志输出格式-->
<pattern>
<pattern>
{
"project": "youlai-mall",
"level": "%level",
"service": "${APP_NAME:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger",
"message": "%message",
"stack_trace": "%exception{20}"
}
</pattern>
</pattern>
</providers>
</encoder>
<!--当有多个LogStash服务时,设置访问策略为轮询-->
<connectionStrategy>
<roundRobin>
<connectionTTL>
5 minutes
</connectionTTL>
</roundRobin>
</connectionStrategy>
</appender>
<!--业务日志输出到LogStash-->
<appender
name=
"LOG_STASH_BUSINESS"
class=
"net.logstash.logback.appender.LogstashTcpSocketAppender"
>
<destination>
${LOG_STASH_HOST}:5044
</destination>
<encoder
charset=
"UTF-8"
class=
"net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"
>
<providers>
<timestamp>
<timeZone>
Asia/Shanghai
</timeZone>
</timestamp>
<!--自定义日志输出格式-->
<pattern>
<pattern>
{
"project": "youlai-mall",
"level": "%level",
"service": "${APP_NAME:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger",
"message": "%message",
"stack_trace": "%exception{20}"
}
</pattern>
</pattern>
</providers>
</encoder>
<!--当有多个LogStash服务时,设置访问策略为轮询-->
<connectionStrategy>
<roundRobin>
<connectionTTL>
5 minutes
</connectionTTL>
</roundRobin>
</connectionStrategy>
</appender>
<!--接口访问记录日志输出到LogStash-->
<appender
name=
"LOG_STASH_RECORD"
class=
"net.logstash.logback.appender.LogstashTcpSocketAppender"
>
<destination>
${LOG_STASH_HOST}:5044
</destination>
<encoder
charset=
"UTF-8"
class=
"net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"
>
<providers>
<timestamp>
<timeZone>
Asia/Shanghai
</timeZone>
</timestamp>
<!--自定义日志输出格式-->
<pattern>
<pattern>
{
"project": "youlai-mall",
"level": "%level",
"service": "${APP_NAME:-}",
"class": "%logger",
"message": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
<!--当有多个LogStash服务时,设置访问策略为轮询-->
<connectionStrategy>
<roundRobin>
<connectionTTL>
5 minutes
</connectionTTL>
</roundRobin>
</connectionStrategy>
</appender>
<!--控制框架输出日志-->
<logger
name=
"org.slf4j"
level=
"INFO"
/>
<logger
name=
"springfox"
level=
"INFO"
/>
<logger
name=
"io.swagger"
level=
"INFO"
/>
<logger
name=
"org.springframework"
level=
"INFO"
/>
<logger
name=
"org.hibernate.validator"
level=
"INFO"
/>
<logger
name=
"com.alibaba.nacos.client.naming"
level=
"INFO"
/>
<root
level=
"DEBUG"
>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE_DEBUG"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
<appender-ref
ref=
"LOG_STASH_DEBUG"
/>
<appender-ref
ref=
"LOG_STASH_ERROR"
/>
</root>
<logger
name=
"com.youlai.common.web.aspect.OptLogAspect"
level=
"DEBUG"
>
<appender-ref
ref=
"LOG_STASH_RECORD"
/>
</logger>
<logger
name=
"com.youlai"
level=
"DEBUG"
>
<appender-ref
ref=
"LOG_STASH_BUSINESS"
/>
</logger>
</configuration>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录