Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Spencer Chang
dp
Commits
b6776e88
Commit
b6776e88
authored
Sep 30, 2020
by
Spencer Chang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[refactor] 类名修改、格式化代码
parent
eb7fefaa
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
18 deletions
+27
-18
README.md
README.md
+1
-1
changLog.md
v2-多线程版本/changLog.md
+1
-1
SysClusterLogFileSubscriber.java
...ava-code/dp/service/impl/SysClusterLogFileSubscriber.java
+8
-3
SysDpDownloadLogServiceImpl.java
...ava-code/dp/service/impl/SysDpDownloadLogServiceImpl.java
+17
-13
No files found.
README.md
View file @
b6776e88
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
### 查询结果直接导出Excel。
### 查询结果直接导出Excel。
### update & delete 语句默认会根据where条件先备份源数据。
### update & delete 语句默认会根据where条件先备份源数据。
### 每次执行的语句都会存储到数据库中(不管是否执行成功),并记录当前执行人ip、用户等信息。
### 每次执行的语句都会存储到数据库中(不管是否执行成功),并记录当前执行人ip、用户等信息。
### 日志下载7天内的leaf.log
### 日志下载7天内的leaf.log
;新增下载当天集群环境所有的日志
## 支持版本
## 支持版本
### Leaf4.1 & Leaf4.2
### Leaf4.1 & Leaf4.2
...
...
v2-多线程版本/changLog.md
View file @
b6776e88
...
@@ -7,6 +7,6 @@
...
@@ -7,6 +7,6 @@
### 2、配置文件 spring/applicationContext-redis.xml 添加:
### 2、配置文件 spring/applicationContext-redis.xml 添加:
```
xml
```
xml
<bean
id=
"sysClusterLogFileProviderImpl"
class=
"com.hand.hls.dp.service.impl.SysClusterLogFile
ProviderImpl
"
/>
<bean
id=
"sysClusterLogFileProviderImpl"
class=
"com.hand.hls.dp.service.impl.SysClusterLogFile
Subscriber
"
/>
```
```
v2-多线程版本/java-code/dp/service/impl/SysClusterLogFile
ProviderImpl
.java
→
v2-多线程版本/java-code/dp/service/impl/SysClusterLogFile
Subscriber
.java
View file @
b6776e88
...
@@ -25,11 +25,16 @@ import java.util.zip.ZipOutputStream;
...
@@ -25,11 +25,16 @@ import java.util.zip.ZipOutputStream;
* @date 2020/9/3 14:32
* @date 2020/9/3 14:32
* @since 1.0
* @since 1.0
*/
*/
@TopicMonitor
(
channel
=
SysClusterLogFile
ProviderImpl
.
LOGFILE_DOWNLOAD
)
@TopicMonitor
(
channel
=
SysClusterLogFile
Subscriber
.
LOGFILE_DOWNLOAD
)
public
class
SysClusterLogFile
ProviderImpl
implements
IMessageConsumer
<
String
>,
InitializingBean
{
public
class
SysClusterLogFile
Subscriber
implements
IMessageConsumer
<
String
>,
InitializingBean
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SysClusterLogFileProviderImpl
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SysClusterLogFileSubscriber
.
class
);
public
static
final
String
LOGFILE_DOWNLOAD
=
"topic:logfile:download"
;
public
static
final
String
LOGFILE_DOWNLOAD
=
"topic:logfile:download"
;
public
static
final
String
LOGFILE_KEY
=
"leaf:logs:zip"
;
public
static
final
String
LOGFILE_KEY
=
"leaf:logs:zip"
;
/**
* @see <a href="https://redis.io/topics/data-types">Data types</a>
* <p>The max length of a list is 2<sup>32</sup> - 1 elements (4294967295, more than 4 billion of elements per list).</p>
*/
private
static
final
long
MAX_LENGTH
=
4294967295L
;
@Value
(
"${log-path}"
)
@Value
(
"${log-path}"
)
private
String
logPath
;
private
String
logPath
;
...
...
v2-多线程版本/java-code/dp/service/impl/SysDpDownloadLogServiceImpl.java
View file @
b6776e88
...
@@ -45,6 +45,7 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
...
@@ -45,6 +45,7 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
/**
/**
* 通知集群服务器当天日志暂存到redis
* 通知集群服务器当天日志暂存到redis
*
* @param requestContext 请求上下文
* @param requestContext 请求上下文
* @param request http请求
* @param request http请求
* @param response http响应
* @param response http响应
...
@@ -52,10 +53,12 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
...
@@ -52,10 +53,12 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
*/
*/
@Override
@Override
public
void
collectLog
(
IRequest
requestContext
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
public
void
collectLog
(
IRequest
requestContext
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
messagePublisher
.
publish
(
SysClusterLogFile
ProviderImpl
.
LOGFILE_DOWNLOAD
,
"download logfile"
);
messagePublisher
.
publish
(
SysClusterLogFile
Subscriber
.
LOGFILE_DOWNLOAD
,
"download logfile"
);
}
}
/**
/**
* 下载集群服务器上当天日志
* 下载集群服务器上当天日志
*
* @param requestContext 请求上下文
* @param requestContext 请求上下文
* @param request http请求
* @param request http请求
* @param response http响应
* @param response http响应
...
@@ -72,10 +75,10 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
...
@@ -72,10 +75,10 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
response
.
setHeader
(
"Expires"
,
"0"
);
response
.
setHeader
(
"Expires"
,
"0"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
zipFileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
zipFileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
response
.
setContentType
(
"application/x-msdownload;"
);
response
.
setContentType
(
"application/x-msdownload;"
);
List
<
String
>
zipFileList
=
redisTemplate
.
opsForList
().
range
(
SysClusterLogFile
ProviderImpl
.
LOGFILE_KEY
,
0
,
-
1
);
List
<
String
>
zipFileList
=
redisTemplate
.
opsForList
().
range
(
SysClusterLogFile
Subscriber
.
LOGFILE_KEY
,
0
,
-
1
);
// 清空
// 清空
while
(
redisTemplate
.
opsForList
().
size
(
SysClusterLogFile
ProviderImpl
.
LOGFILE_KEY
)
>
0
)
{
while
(
redisTemplate
.
opsForList
().
size
(
SysClusterLogFile
Subscriber
.
LOGFILE_KEY
)
>
0
)
{
redisTemplate
.
opsForList
().
leftPop
(
SysClusterLogFile
ProviderImpl
.
LOGFILE_KEY
);
redisTemplate
.
opsForList
().
leftPop
(
SysClusterLogFile
Subscriber
.
LOGFILE_KEY
);
}
}
int
size
=
zipFileList
.
size
();
int
size
=
zipFileList
.
size
();
if
(
size
>=
1
)
{
if
(
size
>=
1
)
{
...
@@ -112,6 +115,7 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
...
@@ -112,6 +115,7 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
/**
/**
* 下载当前请求的服务器上7天日志
* 下载当前请求的服务器上7天日志
*
* @param requestContext 请求上下文
* @param requestContext 请求上下文
* @param request http请求
* @param request http请求
* @param response http响应
* @param response http响应
...
@@ -119,29 +123,29 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
...
@@ -119,29 +123,29 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
*/
*/
@Override
@Override
public
void
download
(
IRequest
requestContext
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
public
void
download
(
IRequest
requestContext
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
String
zipFileName
=
DateUtil
.
format
(
new
Date
(),
"yyyyMMddHHmmss"
)
+
"_logs.zip"
;
String
zipFileName
=
DateUtil
.
format
(
new
Date
(),
"yyyyMMddHHmmss"
)
+
"_logs.zip"
;
response
.
reset
();
response
.
reset
();
response
.
setHeader
(
"Pragma"
,
"No-cache"
);
response
.
setHeader
(
"Pragma"
,
"No-cache"
);
response
.
setHeader
(
"Cache-Control"
,
"no-cache,must-revalidate"
);
response
.
setHeader
(
"Cache-Control"
,
"no-cache,must-revalidate"
);
response
.
setHeader
(
"Expires"
,
"0"
);
response
.
setHeader
(
"Expires"
,
"0"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
zipFileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
zipFileName
.
getBytes
(),
StandardCharsets
.
ISO_8859_1
));
response
.
setContentType
(
"application/x-msdownload;"
);
response
.
setContentType
(
"application/x-msdownload;"
);
ByteArrayOutputStream
byteOutPut
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
byteOutPut
=
new
ByteArrayOutputStream
();
CheckedOutputStream
cos
=
new
CheckedOutputStream
(
byteOutPut
,
new
CRC32
());
CheckedOutputStream
cos
=
new
CheckedOutputStream
(
byteOutPut
,
new
CRC32
());
ZipOutputStream
zos
=
new
ZipOutputStream
(
cos
);
ZipOutputStream
zos
=
new
ZipOutputStream
(
cos
);
// 下载7天内的日志
// 下载7天内的日志
String
[]
downloadFiles
=
new
String
[
7
];
String
[]
downloadFiles
=
new
String
[
7
];
int
length
=
downloadFiles
.
length
;
int
length
=
downloadFiles
.
length
;
// 当前日志
// 当前日志
downloadFiles
[
0
]
=
logPath
+
"leaf.log"
;
downloadFiles
[
0
]
=
logPath
+
"leaf.log"
;
for
(
int
i
=
1
;
i
<=
length
-
1
;
i
++)
{
for
(
int
i
=
1
;
i
<=
length
-
1
;
i
++)
{
LocalDate
tmp
=
LocalDate
.
now
().
minusDays
(
i
);
LocalDate
tmp
=
LocalDate
.
now
().
minusDays
(
i
);
Date
date
=
Date
.
from
(
tmp
.
atStartOfDay
().
atZone
(
ZoneId
.
systemDefault
()).
toInstant
());
Date
date
=
Date
.
from
(
tmp
.
atStartOfDay
().
atZone
(
ZoneId
.
systemDefault
()).
toInstant
());
downloadFiles
[
i
]
=
logPath
+
"leaf-"
+
DateUtil
.
format
(
date
,
"yyyy-MM-dd"
)
+
".log"
;
downloadFiles
[
i
]
=
logPath
+
"leaf-"
+
DateUtil
.
format
(
date
,
"yyyy-MM-dd"
)
+
".log"
;
}
}
// 查找日志目录下所有文件
// 查找日志目录下所有文件
List
<
String
>
files
=
new
ArrayList
<>(
31
);
List
<
String
>
files
=
new
ArrayList
<>(
31
);
LogUtils
.
findFiles
(
new
File
(
logPath
),
files
);
LogUtils
.
findFiles
(
new
File
(
logPath
),
files
);
files
.
forEach
(
file
->
{
files
.
forEach
(
file
->
{
for
(
String
downloadFile
:
downloadFiles
)
{
for
(
String
downloadFile
:
downloadFiles
)
{
if
(
file
.
equals
(
downloadFile
))
{
if
(
file
.
equals
(
downloadFile
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment