Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-module-file
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-module-file
Commits
dda64b52
提交
dda64b52
authored
10月 09, 2024
作者:
李秋林
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
初始化代码
上级
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
737 行增加
和
0 行删除
+737
-0
pom.xml
pom.xml
+92
-0
SfaFileApplication.java
src/main/java/com/sfa/file/SfaFileApplication.java
+19
-0
MinioConfig.java
src/main/java/com/sfa/file/config/MinioConfig.java
+82
-0
ResourcesConfig.java
src/main/java/com/sfa/file/config/ResourcesConfig.java
+51
-0
SysFileController.java
src/main/java/com/sfa/file/controller/SysFileController.java
+49
-0
FastDfsSysFileServiceImpl.java
.../java/com/sfa/file/service/FastDfsSysFileServiceImpl.java
+46
-0
ISysFileService.java
src/main/java/com/sfa/file/service/ISysFileService.java
+20
-0
LocalSysFileServiceImpl.java
...in/java/com/sfa/file/service/LocalSysFileServiceImpl.java
+50
-0
MinioSysFileServiceImpl.java
...in/java/com/sfa/file/service/MinioSysFileServiceImpl.java
+49
-0
FileUploadUtils.java
src/main/java/com/sfa/file/utils/FileUploadUtils.java
+186
-0
bootstrap-dev.yml
src/main/resources/bootstrap-dev.yml
+15
-0
bootstrap.yml
src/main/resources/bootstrap.yml
+3
-0
logback.xml
src/main/resources/logback.xml
+75
-0
没有找到文件。
pom.xml
0 → 100644
浏览文件 @
dda64b52
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.wangxiaolu.sfa
</groupId>
<artifactId>
wangxiaolu-sfa-parent
</artifactId>
<version>
0.0.1
</version>
<relativePath/>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<name>
wangxiaolu-sfa-module-file
</name>
<artifactId>
wangxiaolu-sfa-module-file
</artifactId>
<version>
0.0.1
</version>
<description>
wangxiaolu-sfa-module-file文件服务
</description>
<dependencies>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<!-- SpringBoot Web -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!-- FastDFS -->
<dependency>
<groupId>
com.github.tobato
</groupId>
<artifactId>
fastdfs-client
</artifactId>
</dependency>
<!-- Minio -->
<dependency>
<groupId>
io.minio
</groupId>
<artifactId>
minio
</artifactId>
<version>
${minio.version}
</version>
</dependency>
<!-- RuoYi Api System -->
<dependency>
<groupId>
com.wangxiaolu.sfa
</groupId>
<artifactId>
wangxiaolu-sfa-api-system
</artifactId>
</dependency>
</dependencies>
<build>
<finalName>
${project.artifactId}
</finalName>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
src/main/java/com/sfa/file/SfaFileApplication.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
/**
* 文件服务
*
* @author ruoyi
*/
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
public
class
SfaFileApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SfaFileApplication
.
class
,
args
);
}
}
src/main/java/com/sfa/file/config/MinioConfig.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
io.minio.MinioClient
;
/**
* Minio 配置信息
*
* @author ruoyi
*/
@Configuration
@ConfigurationProperties
(
prefix
=
"minio"
)
public
class
MinioConfig
{
/**
* 服务地址
*/
private
String
url
;
/**
* 用户名
*/
private
String
accessKey
;
/**
* 密码
*/
private
String
secretKey
;
/**
* 存储桶名称
*/
private
String
bucketName
;
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getAccessKey
()
{
return
accessKey
;
}
public
void
setAccessKey
(
String
accessKey
)
{
this
.
accessKey
=
accessKey
;
}
public
String
getSecretKey
()
{
return
secretKey
;
}
public
void
setSecretKey
(
String
secretKey
)
{
this
.
secretKey
=
secretKey
;
}
public
String
getBucketName
()
{
return
bucketName
;
}
public
void
setBucketName
(
String
bucketName
)
{
this
.
bucketName
=
bucketName
;
}
@Bean
public
MinioClient
getMinioClient
()
{
return
MinioClient
.
builder
().
endpoint
(
url
).
credentials
(
accessKey
,
secretKey
).
build
();
}
}
src/main/java/com/sfa/file/config/ResourcesConfig.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
config
;
import
java.io.File
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
/**
* 通用映射配置
*
* @author ruoyi
*/
@Configuration
public
class
ResourcesConfig
implements
WebMvcConfigurer
{
/**
* 上传文件存储在本地的根路径
*/
@Value
(
"${file.path}"
)
private
String
localFilePath
;
/**
* 资源映射路径 前缀
*/
@Value
(
"${file.prefix}"
)
public
String
localFilePrefix
;
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
/** 本地文件上传路径 */
registry
.
addResourceHandler
(
localFilePrefix
+
"/**"
)
.
addResourceLocations
(
"file:"
+
localFilePath
+
File
.
separator
);
}
/**
* 开启跨域
*/
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
// 设置允许跨域的路由
registry
.
addMapping
(
localFilePrefix
+
"/**"
)
// 设置允许跨域请求的域名
.
allowedOrigins
(
"*"
)
// 设置允许的方法
.
allowedMethods
(
"GET"
);
}
}
\ No newline at end of file
src/main/java/com/sfa/file/controller/SysFileController.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
controller
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.sfa.common.core.domain.R
;
import
com.sfa.common.core.utils.file.FileUtils
;
import
com.sfa.file.service.ISysFileService
;
import
com.sfa.system.api.domain.SysFile
;
/**
* 文件请求处理
*
* @author ruoyi
*/
@RestController
public
class
SysFileController
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SysFileController
.
class
);
@Autowired
private
ISysFileService
sysFileService
;
/**
* 文件上传请求
*/
@PostMapping
(
"upload"
)
public
R
<
SysFile
>
upload
(
MultipartFile
file
)
{
try
{
// 上传并返回访问地址
String
url
=
sysFileService
.
uploadFile
(
file
);
SysFile
sysFile
=
new
SysFile
();
sysFile
.
setName
(
FileUtils
.
getName
(
url
));
sysFile
.
setUrl
(
url
);
return
R
.
ok
(
sysFile
);
}
catch
(
Exception
e
)
{
log
.
error
(
"上传文件失败"
,
e
);
return
R
.
fail
(
e
.
getMessage
());
}
}
}
\ No newline at end of file
src/main/java/com/sfa/file/service/FastDfsSysFileServiceImpl.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
service
;
import
java.io.InputStream
;
import
com.alibaba.nacos.common.utils.IoUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.github.tobato.fastdfs.domain.fdfs.StorePath
;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
import
com.sfa.common.core.utils.file.FileTypeUtils
;
/**
* FastDFS 文件存储
*
* @author ruoyi
*/
@Service
public
class
FastDfsSysFileServiceImpl
implements
ISysFileService
{
/**
* 域名或本机访问地址
*/
@Value
(
"${fdfs.domain}"
)
public
String
domain
;
@Autowired
private
FastFileStorageClient
storageClient
;
/**
* FastDfs文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
@Override
public
String
uploadFile
(
MultipartFile
file
)
throws
Exception
{
InputStream
inputStream
=
file
.
getInputStream
();
StorePath
storePath
=
storageClient
.
uploadFile
(
inputStream
,
file
.
getSize
(),
FileTypeUtils
.
getExtension
(
file
),
null
);
IoUtils
.
closeQuietly
(
inputStream
);
return
domain
+
"/"
+
storePath
.
getFullPath
();
}
}
src/main/java/com/sfa/file/service/ISysFileService.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
service
;
import
org.springframework.web.multipart.MultipartFile
;
/**
* 文件上传接口
*
* @author ruoyi
*/
public
interface
ISysFileService
{
/**
* 文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
public
String
uploadFile
(
MultipartFile
file
)
throws
Exception
;
}
src/main/java/com/sfa/file/service/LocalSysFileServiceImpl.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
service
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.sfa.file.utils.FileUploadUtils
;
/**
* 本地文件存储
*
* @author ruoyi
*/
@Primary
@Service
public
class
LocalSysFileServiceImpl
implements
ISysFileService
{
/**
* 资源映射路径 前缀
*/
@Value
(
"${file.prefix}"
)
public
String
localFilePrefix
;
/**
* 域名或本机访问地址
*/
@Value
(
"${file.domain}"
)
public
String
domain
;
/**
* 上传文件存储在本地的根路径
*/
@Value
(
"${file.path}"
)
private
String
localFilePath
;
/**
* 本地文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
@Override
public
String
uploadFile
(
MultipartFile
file
)
throws
Exception
{
String
name
=
FileUploadUtils
.
upload
(
localFilePath
,
file
);
String
url
=
domain
+
localFilePrefix
+
name
;
return
url
;
}
}
src/main/java/com/sfa/file/service/MinioSysFileServiceImpl.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
service
;
import
java.io.InputStream
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.alibaba.nacos.common.utils.IoUtils
;
import
com.sfa.file.config.MinioConfig
;
import
com.sfa.file.utils.FileUploadUtils
;
import
io.minio.MinioClient
;
import
io.minio.PutObjectArgs
;
/**
* Minio 文件存储
*
* @author ruoyi
*/
@Service
public
class
MinioSysFileServiceImpl
implements
ISysFileService
{
@Autowired
private
MinioConfig
minioConfig
;
@Autowired
private
MinioClient
client
;
/**
* Minio文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
@Override
public
String
uploadFile
(
MultipartFile
file
)
throws
Exception
{
String
fileName
=
FileUploadUtils
.
extractFilename
(
file
);
InputStream
inputStream
=
file
.
getInputStream
();
PutObjectArgs
args
=
PutObjectArgs
.
builder
()
.
bucket
(
minioConfig
.
getBucketName
())
.
object
(
fileName
)
.
stream
(
inputStream
,
file
.
getSize
(),
-
1
)
.
contentType
(
file
.
getContentType
())
.
build
();
client
.
putObject
(
args
);
IoUtils
.
closeQuietly
(
inputStream
);
return
minioConfig
.
getUrl
()
+
"/"
+
minioConfig
.
getBucketName
()
+
"/"
+
fileName
;
}
}
src/main/java/com/sfa/file/utils/FileUploadUtils.java
0 → 100644
浏览文件 @
dda64b52
package
com
.
sfa
.
file
.
utils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
import
java.util.Objects
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.sfa.common.core.exception.file.FileException
;
import
com.sfa.common.core.exception.file.FileNameLengthLimitExceededException
;
import
com.sfa.common.core.exception.file.FileSizeLimitExceededException
;
import
com.sfa.common.core.exception.file.InvalidExtensionException
;
import
com.sfa.common.core.utils.DateUtils
;
import
com.sfa.common.core.utils.StringUtils
;
import
com.sfa.common.core.utils.file.FileTypeUtils
;
import
com.sfa.common.core.utils.file.MimeTypeUtils
;
import
com.sfa.common.core.utils.uuid.Seq
;
/**
* 文件上传工具类
*
* @author ruoyi
*/
public
class
FileUploadUtils
{
/**
* 默认大小 50M
*/
public
static
final
long
DEFAULT_MAX_SIZE
=
50
*
1024
*
1024L
;
/**
* 默认的文件名最大长度 100
*/
public
static
final
int
DEFAULT_FILE_NAME_LENGTH
=
100
;
/**
* 根据文件路径上传
*
* @param baseDir 相对应用的基目录
* @param file 上传的文件
* @return 文件名称
* @throws IOException
*/
public
static
final
String
upload
(
String
baseDir
,
MultipartFile
file
)
throws
IOException
{
try
{
return
upload
(
baseDir
,
file
,
MimeTypeUtils
.
DEFAULT_ALLOWED_EXTENSION
);
}
catch
(
FileException
fe
)
{
throw
new
IOException
(
fe
.
getDefaultMessage
(),
fe
);
}
catch
(
Exception
e
)
{
throw
new
IOException
(
e
.
getMessage
(),
e
);
}
}
/**
* 文件上传
*
* @param baseDir 相对应用的基目录
* @param file 上传的文件
* @param allowedExtension 上传文件类型
* @return 返回上传成功的文件名
* @throws FileSizeLimitExceededException 如果超出最大大小
* @throws FileNameLengthLimitExceededException 文件名太长
* @throws IOException 比如读写文件出错时
* @throws InvalidExtensionException 文件校验异常
*/
public
static
final
String
upload
(
String
baseDir
,
MultipartFile
file
,
String
[]
allowedExtension
)
throws
FileSizeLimitExceededException
,
IOException
,
FileNameLengthLimitExceededException
,
InvalidExtensionException
{
int
fileNamelength
=
Objects
.
requireNonNull
(
file
.
getOriginalFilename
()).
length
();
if
(
fileNamelength
>
FileUploadUtils
.
DEFAULT_FILE_NAME_LENGTH
)
{
throw
new
FileNameLengthLimitExceededException
(
FileUploadUtils
.
DEFAULT_FILE_NAME_LENGTH
);
}
assertAllowed
(
file
,
allowedExtension
);
String
fileName
=
extractFilename
(
file
);
String
absPath
=
getAbsoluteFile
(
baseDir
,
fileName
).
getAbsolutePath
();
file
.
transferTo
(
Paths
.
get
(
absPath
));
return
getPathFileName
(
fileName
);
}
/**
* 编码文件名
*/
public
static
final
String
extractFilename
(
MultipartFile
file
)
{
return
StringUtils
.
format
(
"{}/{}_{}.{}"
,
DateUtils
.
datePath
(),
FilenameUtils
.
getBaseName
(
file
.
getOriginalFilename
()),
Seq
.
getId
(
Seq
.
uploadSeqType
),
FileTypeUtils
.
getExtension
(
file
));
}
private
static
final
File
getAbsoluteFile
(
String
uploadDir
,
String
fileName
)
throws
IOException
{
File
desc
=
new
File
(
uploadDir
+
File
.
separator
+
fileName
);
if
(!
desc
.
exists
())
{
if
(!
desc
.
getParentFile
().
exists
())
{
desc
.
getParentFile
().
mkdirs
();
}
}
return
desc
.
isAbsolute
()
?
desc
:
desc
.
getAbsoluteFile
();
}
private
static
final
String
getPathFileName
(
String
fileName
)
throws
IOException
{
String
pathFileName
=
"/"
+
fileName
;
return
pathFileName
;
}
/**
* 文件大小校验
*
* @param file 上传的文件
* @throws FileSizeLimitExceededException 如果超出最大大小
* @throws InvalidExtensionException 文件校验异常
*/
public
static
final
void
assertAllowed
(
MultipartFile
file
,
String
[]
allowedExtension
)
throws
FileSizeLimitExceededException
,
InvalidExtensionException
{
long
size
=
file
.
getSize
();
if
(
size
>
DEFAULT_MAX_SIZE
)
{
throw
new
FileSizeLimitExceededException
(
DEFAULT_MAX_SIZE
/
1024
/
1024
);
}
String
fileName
=
file
.
getOriginalFilename
();
String
extension
=
FileTypeUtils
.
getExtension
(
file
);
if
(
allowedExtension
!=
null
&&
!
isAllowedExtension
(
extension
,
allowedExtension
))
{
if
(
allowedExtension
==
MimeTypeUtils
.
IMAGE_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidImageExtensionException
(
allowedExtension
,
extension
,
fileName
);
}
else
if
(
allowedExtension
==
MimeTypeUtils
.
FLASH_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidFlashExtensionException
(
allowedExtension
,
extension
,
fileName
);
}
else
if
(
allowedExtension
==
MimeTypeUtils
.
MEDIA_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidMediaExtensionException
(
allowedExtension
,
extension
,
fileName
);
}
else
if
(
allowedExtension
==
MimeTypeUtils
.
VIDEO_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidVideoExtensionException
(
allowedExtension
,
extension
,
fileName
);
}
else
{
throw
new
InvalidExtensionException
(
allowedExtension
,
extension
,
fileName
);
}
}
}
/**
* 判断MIME类型是否是允许的MIME类型
*
* @param extension 上传文件类型
* @param allowedExtension 允许上传文件类型
* @return true/false
*/
public
static
final
boolean
isAllowedExtension
(
String
extension
,
String
[]
allowedExtension
)
{
for
(
String
str
:
allowedExtension
)
{
if
(
str
.
equalsIgnoreCase
(
extension
))
{
return
true
;
}
}
return
false
;
}
}
\ No newline at end of file
src/main/resources/bootstrap-dev.yml
0 → 100644
浏览文件 @
dda64b52
spring
:
application
:
name
:
wangxiaolu-sfa-file
cloud
:
nacos
:
discovery
:
server-addr
:
sfa.test.wxl66.cn:8848
group
:
sfa
namespace
:
db2a5aa4-e380-4787-9214-1c394f99ffb4
config
:
server-addr
:
sfa.test.wxl66.cn:8848
file-extension
:
yaml
group
:
sfa
namespace
:
db2a5aa4-e380-4787-9214-1c394f99ffb4
src/main/resources/bootstrap.yml
0 → 100644
浏览文件 @
dda64b52
spring
:
profiles
:
active
:
dev
src/main/resources/logback.xml
0 → 100644
浏览文件 @
dda64b52
<?xml version="1.0" encoding="UTF-8"?>
<configuration
scan=
"true"
scanPeriod=
"60 seconds"
debug=
"false"
>
<!-- 日志存放路径 -->
<property
name=
"log.path"
value=
"logs/wangxiaolu-sfa-file"
/>
<!-- 日志输出格式 -->
<property
name=
"log.pattern"
value=
"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"
/>
<!-- 控制台输出 -->
<appender
name=
"console"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
${log.pattern}
</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender
name=
"file_info"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${log.path}/info.log
</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 日志文件名格式 -->
<fileNamePattern>
${log.path}/info.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>
60
</maxHistory>
</rollingPolicy>
<encoder>
<pattern>
${log.pattern}
</pattern>
</encoder>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<!-- 过滤的级别 -->
<level>
INFO
</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>
ACCEPT
</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>
DENY
</onMismatch>
</filter>
</appender>
<appender
name=
"file_error"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${log.path}/error.log
</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 日志文件名格式 -->
<fileNamePattern>
${log.path}/error.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>
60
</maxHistory>
</rollingPolicy>
<encoder>
<pattern>
${log.pattern}
</pattern>
</encoder>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<!-- 过滤的级别 -->
<level>
ERROR
</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>
ACCEPT
</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>
DENY
</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger
name=
"com.sfa"
level=
"info"
/>
<!-- Spring日志级别控制 -->
<logger
name=
"org.springframework"
level=
"warn"
/>
<root
level=
"info"
>
<appender-ref
ref=
"console"
/>
</root>
<!--系统操作日志-->
<root
level=
"info"
>
<appender-ref
ref=
"file_info"
/>
<appender-ref
ref=
"file_error"
/>
</root>
</configuration>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论