Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
xxl-job
提交
ae26cb0c
X
xxl-job
项目概览
OpenDocCN
/
xxl-job
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
xxl-job
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ae26cb0c
编写于
3月 23, 2017
作者:
X
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
日志rollback展示
上级
049091c4
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
302 addition
and
93 deletion
+302
-93
doc/images/qq群-一个xxl同学进了58.png
doc/images/qq群-一个xxl同学进了58.png
+0
-0
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java
...n/java/com/xxl/job/admin/controller/JobLogController.java
+30
-30
xxl-job-admin/src/main/webapp/WEB-INF/template/joblog/logdetail.ftl
...min/src/main/webapp/WEB-INF/template/joblog/logdetail.ftl
+94
-6
xxl-job-admin/src/main/webapp/static/js/logdetail.index.1.js
xxl-job-admin/src/main/webapp/static/js/logdetail.index.1.js
+78
-0
xxl-job-core/src/main/java/com/xxl/job/core/biz/ExecutorBiz.java
...-core/src/main/java/com/xxl/job/core/biz/ExecutorBiz.java
+3
-1
xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
.../main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
+4
-3
xxl-job-core/src/main/java/com/xxl/job/core/biz/model/LogResult.java
...e/src/main/java/com/xxl/job/core/biz/model/LogResult.java
+47
-0
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
...rc/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
+46
-53
未找到文件。
doc/images/qq群-一个xxl同学进了58.png
0 → 100644
浏览文件 @
ae26cb0c
438.0 KB
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobLogController.java
浏览文件 @
ae26cb0c
...
@@ -7,6 +7,7 @@ import com.xxl.job.admin.dao.IXxlJobGroupDao;
...
@@ -7,6 +7,7 @@ import com.xxl.job.admin.dao.IXxlJobGroupDao;
import
com.xxl.job.admin.dao.IXxlJobInfoDao
;
import
com.xxl.job.admin.dao.IXxlJobInfoDao
;
import
com.xxl.job.admin.dao.IXxlJobLogDao
;
import
com.xxl.job.admin.dao.IXxlJobLogDao
;
import
com.xxl.job.core.biz.ExecutorBiz
;
import
com.xxl.job.core.biz.ExecutorBiz
;
import
com.xxl.job.core.biz.model.LogResult
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.rpc.netcom.NetComClientProxy
;
import
com.xxl.job.core.rpc.netcom.NetComClientProxy
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
...
@@ -93,42 +94,41 @@ public class JobLogController {
...
@@ -93,42 +94,41 @@ public class JobLogController {
return
maps
;
return
maps
;
}
}
@RequestMapping
(
"/logDetail"
)
@RequestMapping
(
"/logDetail
Page
"
)
@ResponseBody
public
String
logDetailPage
(
int
id
,
Model
model
){
public
ReturnT
<
String
>
logDetail
(
int
id
){
// base check
// base check
XxlJobLog
log
=
xxlJobLogDao
.
load
(
id
);
ReturnT
<
String
>
logStatue
=
ReturnT
.
SUCCESS
;
if
(
log
==
null
)
{
XxlJobLog
jobLog
=
xxlJobLogDao
.
load
(
id
);
return
new
ReturnT
<
String
>(
500
,
"查看执行日志失败: 参数异常"
);
if
(
jobLog
==
null
)
{
logStatue
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"查看执行日志失败: 日志ID非法"
);
}
else
{
if
(
ReturnT
.
SUCCESS_CODE
!=
jobLog
.
getTriggerCode
())
{
logStatue
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"查看执行日志失败: 任务发起调度失败,无法查看执行日志"
);
}
}
if
(
ReturnT
.
SUCCESS_CODE
!=
log
.
getTriggerCode
())
{
return
new
ReturnT
<
String
>(
500
,
"查看执行日志失败: 任务发起调度失败,无法查看执行日志"
);
model
.
addAttribute
(
"executorAddress"
,
jobLog
.
getExecutorAddress
());
model
.
addAttribute
(
"triggerTime"
,
jobLog
.
getTriggerTime
().
getTime
());
model
.
addAttribute
(
"logId"
,
jobLog
.
getId
());
}
}
// trigger id, trigger time
model
.
addAttribute
(
"logStatue"
,
logStatue
);
ExecutorBiz
executorBiz
=
null
;
return
"joblog/logdetail"
;
}
@RequestMapping
(
"/logDetailCat"
)
@ResponseBody
public
ReturnT
<
LogResult
>
logDetailCat
(
String
executorAddress
,
long
triggerTime
,
int
logId
,
int
fromLineNum
){
try
{
try
{
executorBiz
=
(
ExecutorBiz
)
new
NetComClientProxy
(
ExecutorBiz
.
class
,
log
.
getExecutorAddress
()).
getObject
();
ExecutorBiz
executorBiz
=
(
ExecutorBiz
)
new
NetComClientProxy
(
ExecutorBiz
.
class
,
executorAddress
).
getObject
();
ReturnT
<
LogResult
>
logResult
=
executorBiz
.
log
(
triggerTime
,
logId
,
fromLineNum
);
return
logResult
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
new
ReturnT
<
String
>(
500
,
e
.
getMessage
());
return
new
ReturnT
<
LogResult
>(
ReturnT
.
FAIL_CODE
,
e
.
getMessage
());
}
ReturnT
<
String
>
logResult
=
executorBiz
.
log
(
log
.
getTriggerTime
().
getTime
(),
id
);
if
(
ReturnT
.
SUCCESS_CODE
==
logResult
.
getCode
())
{
return
new
ReturnT
<
String
>(
logResult
.
getMsg
());
}
else
{
return
new
ReturnT
<
String
>(
500
,
"查看执行日志失败: "
+
logResult
.
getMsg
());
}
}
}
}
@RequestMapping
(
"/logDetailPage"
)
public
String
logDetailPage
(
int
id
,
Model
model
){
ReturnT
<
String
>
data
=
logDetail
(
id
);
model
.
addAttribute
(
"result"
,
data
);
return
"joblog/logdetail"
;
}
@RequestMapping
(
"/logKill"
)
@RequestMapping
(
"/logKill"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
logKill
(
int
id
){
public
ReturnT
<
String
>
logKill
(
int
id
){
...
...
xxl-job-admin/src/main/webapp/WEB-INF/template/joblog/logdetail.ftl
浏览文件 @
ae26cb0c
<body style="color:white;background-color:black;" >
<!DOCTYPE html>
<pre>
<html>
<br>
<head>
<#if result.code == 200>${result.content}
<title>
任务调度中心
</title>
<#else>${result.msg}</#if>
<
#import
"/
common
/
common.macro.ftl
"
as
netCommon
>
</pre>
<
@
netCommon.commonStyle
/>
<style
type=
"text/css"
>
.logConsolePre
{
font-size
:
12px
;
width
:
100%
;
height
:
100%
;
/*bottom: 0;
top: 0px;*/
position
:
absolute
;
/*color:white;background-color:black*/
}
.logConsoleRunning
{
font-size
:
20px
;
margin-top
:
7px
;
}
</style>
</head>
<body
class=
"skin-blue fixed layout-top-nav"
>
<div
class=
"wrapper"
>
<header
class=
"main-header"
>
<nav
class=
"navbar navbar-static-top"
>
<div
class=
"container"
>
<
#--
icon
--
>
<div
class=
"navbar-header"
>
<a
href=
"../../index2.html"
class=
"navbar-brand"
><b>
日志
</b>
Console
</a>
<button
type=
"button"
class=
"navbar-toggle collapsed"
data-toggle=
"collapse"
data-target=
"#navbar-collapse"
>
<i
class=
"fa fa-bars"
></i>
</button>
</div>
<
#--
left
nav
--
>
<div
class=
"collapse navbar-collapse pull-left"
id=
"navbar-collapse"
>
<ul
class=
"nav navbar-nav"
>
<
#--
<
li
class=
"active"
><a
href=
"javascript:;"
>
任务:
<span
class=
"sr-only"
>
(current)
</span></a></li>
-->
</ul>
</div>
<
#--
right
nav
--
>
<div
class=
"navbar-custom-menu"
>
<ul
class=
"nav navbar-nav"
>
<li>
<a
href=
"javascript:window.location.reload();"
>
<i
class=
"fa fa-fw fa-refresh"
></i>
刷新
</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div
class=
"content-wrapper"
>
<pre
class=
"logConsolePre"
><div
id=
"logConsole"
></div><li
class=
"fa fa-refresh fa-spin logConsoleRunning"
></li></pre>
</div>
</div>
<
@
netCommon.commonScript
/>
<script>
// 参数
var
running
=
true
;
// 允许运行
var
executorAddress
;
var
triggerTime
;
var
logId
;
// init
<
#
if
logStatue
.
code
==
200
>
running
=
true
;
$
(
'
.logConsoleRunning
'
).
show
();
executorAddress
=
'
${executorAddress}
'
;
triggerTime
=
'
${triggerTime}
'
;
logId
=
'
${logId}
'
;
<
#
else
>
running
=
false
;
$
(
'
.logConsoleRunning
'
).
hide
();
$
(
'
.logConsole
'
).
append
(
'
${logStatue.msg}
'
);
<
/#if>
</script>
<script
src=
"${request.contextPath}/static/js/logdetail.index.1.js"
></script>
</body>
</body>
</html>
\ No newline at end of file
xxl-job-admin/src/main/webapp/static/js/logdetail.index.1.js
0 → 100644
浏览文件 @
ae26cb0c
$
(
function
()
{
// valid
if
(
!
running
)
{
return
;
}
// 加载日志
var
fromLineNum
=
0
;
var
pullFailCount
=
0
;
function
pullLog
()
{
// pullFailCount, max=20
if
(
pullFailCount
>=
20
)
{
console
.
log
(
"
pullLog fail-count limit
"
);
running
=
false
;
}
// valid
if
(
!
running
)
{
$
(
'
.logConsoleRunning
'
).
hide
();
logRun
=
window
.
clearInterval
(
logRun
)
return
;
}
// load
console
.
log
(
"
pullLog, fromLineNum:
"
+
fromLineNum
);
$
.
ajax
({
type
:
'
POST
'
,
async
:
false
,
// async, avoid js invoke pagelist before jobId data init
url
:
base_url
+
'
/joblog/logDetailCat
'
,
data
:
{
"
executorAddress
"
:
executorAddress
,
"
triggerTime
"
:
triggerTime
,
"
logId
"
:
logId
,
"
fromLineNum
"
:
fromLineNum
},
dataType
:
"
json
"
,
success
:
function
(
data
){
pullFailCount
++
;
if
(
data
.
code
==
200
)
{
if
(
!
data
.
content
)
{
console
.
log
(
'
pullLog fail
'
);
return
;
}
if
(
fromLineNum
!=
data
.
content
.
fromLineNum
)
{
console
.
log
(
'
pullLog fromLineNum not match
'
);
return
;
}
if
(
fromLineNum
==
(
data
.
content
.
toLineNum
+
1
)
)
{
console
.
log
(
'
pullLog already line-end
'
);
return
;
}
// append
fromLineNum
=
data
.
content
.
toLineNum
+
1
;
$
(
'
#logConsole
'
).
append
(
data
.
content
.
logContent
);
pullFailCount
=
0
;
// valid end
if
(
data
.
content
.
end
)
{
running
=
false
;
console
.
log
(
"
pullLog already file-end
"
);
}
}
else
{
ComAlertTec
.
show
(
data
.
msg
);
}
}
});
}
// 周期运行
pullLog
();
var
logRun
=
setInterval
(
function
()
{
pullLog
()
},
3000
);
});
xxl-job-core/src/main/java/com/xxl/job/core/biz/ExecutorBiz.java
浏览文件 @
ae26cb0c
package
com.xxl.job.core.biz
;
package
com.xxl.job.core.biz
;
import
com.xxl.job.core.biz.model.LogResult
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.TriggerParam
;
import
com.xxl.job.core.biz.model.TriggerParam
;
...
@@ -25,9 +26,10 @@ public interface ExecutorBiz {
...
@@ -25,9 +26,10 @@ public interface ExecutorBiz {
* log
* log
* @param logDateTim
* @param logDateTim
* @param logId
* @param logId
* @param fromLineNum
* @return
* @return
*/
*/
public
ReturnT
<
String
>
log
(
long
logDateTim
,
int
logId
);
public
ReturnT
<
LogResult
>
log
(
long
logDateTim
,
int
logId
,
int
fromLineNum
);
/**
/**
* run
* run
...
...
xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
浏览文件 @
ae26cb0c
package
com.xxl.job.core.biz.impl
;
package
com.xxl.job.core.biz.impl
;
import
com.xxl.job.core.biz.ExecutorBiz
;
import
com.xxl.job.core.biz.ExecutorBiz
;
import
com.xxl.job.core.biz.model.LogResult
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.TriggerParam
;
import
com.xxl.job.core.biz.model.TriggerParam
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
...
@@ -42,12 +43,12 @@ public class ExecutorBizImpl implements ExecutorBiz {
...
@@ -42,12 +43,12 @@ public class ExecutorBizImpl implements ExecutorBiz {
}
}
@Override
@Override
public
ReturnT
<
String
>
log
(
long
logDateTim
,
int
logId
)
{
public
ReturnT
<
LogResult
>
log
(
long
logDateTim
,
int
logId
,
int
fromLineNum
)
{
// log filename: yyyy-MM-dd/9999.log
// log filename: yyyy-MM-dd/9999.log
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
logDateTim
),
logId
);
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
logDateTim
),
logId
);
String
logConteng
=
XxlJobFileAppender
.
readLog
(
logFileName
);
LogResult
logResult
=
XxlJobFileAppender
.
readLog
(
logFileName
,
fromLineNum
);
return
new
ReturnT
<
String
>(
ReturnT
.
SUCCESS_CODE
,
logConteng
);
return
new
ReturnT
<
LogResult
>(
logResult
);
}
}
@Override
@Override
...
...
xxl-job-core/src/main/java/com/xxl/job/core/biz/model/LogResult.java
0 → 100644
浏览文件 @
ae26cb0c
package
com.xxl.job.core.biz.model
;
import
java.io.Serializable
;
/**
* Created by xuxueli on 17/3/23.
*/
public
class
LogResult
implements
Serializable
{
private
static
final
long
serialVersionUID
=
42L
;
private
int
fromLineNum
;
private
int
toLineNum
;
private
String
logContent
;
private
boolean
isEnd
;
public
int
getFromLineNum
()
{
return
fromLineNum
;
}
public
void
setFromLineNum
(
int
fromLineNum
)
{
this
.
fromLineNum
=
fromLineNum
;
}
public
int
getToLineNum
()
{
return
toLineNum
;
}
public
void
setToLineNum
(
int
toLineNum
)
{
this
.
toLineNum
=
toLineNum
;
}
public
String
getLogContent
()
{
return
logContent
;
}
public
void
setLogContent
(
String
logContent
)
{
this
.
logContent
=
logContent
;
}
public
boolean
isEnd
()
{
return
isEnd
;
}
public
void
setEnd
(
boolean
end
)
{
isEnd
=
end
;
}
}
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
浏览文件 @
ae26cb0c
package
com.xxl.job.core.log
;
package
com.xxl.job.core.log
;
import
com.xxl.job.core.biz.model.LogResult
;
import
org.apache.log4j.AppenderSkeleton
;
import
org.apache.log4j.AppenderSkeleton
;
import
org.apache.log4j.Layout
;
import
org.apache.log4j.Layout
;
import
org.apache.log4j.spi.LoggingEvent
;
import
org.apache.log4j.spi.LoggingEvent
;
...
@@ -117,8 +118,9 @@ public class XxlJobFileAppender extends AppenderSkeleton {
...
@@ -117,8 +118,9 @@ public class XxlJobFileAppender extends AppenderSkeleton {
* @param logFileName
* @param logFileName
* @return log content
* @return log content
*/
*/
public
static
String
readLog
(
String
logFileName
){
public
static
LogResult
readLog
(
String
logFileName
,
int
fromLineNum
){
// valid log file
if
(
logFileName
==
null
||
logFileName
.
trim
().
length
()==
0
)
{
if
(
logFileName
==
null
||
logFileName
.
trim
().
length
()==
0
)
{
return
null
;
return
null
;
}
}
...
@@ -128,26 +130,19 @@ public class XxlJobFileAppender extends AppenderSkeleton {
...
@@ -128,26 +130,19 @@ public class XxlJobFileAppender extends AppenderSkeleton {
return
null
;
return
null
;
}
}
String
logData
=
readLines
(
logFile
);
// read file
return
logData
;
StringBuffer
logContentBuffer
=
new
StringBuffer
();
}
int
toLineNum
=
0
;
LineNumberReader
reader
=
null
;
/**
* read log data
* @param logFile
* @return log line content
*/
public
static
String
readLines
(
File
logFile
){
BufferedReader
reader
=
null
;
try
{
try
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
logFile
),
"utf-8"
));
reader
=
new
LineNumberReader
(
new
FileReader
(
logFile
));
if
(
reader
!=
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
).
append
(
"\n"
);
while
((
line
=
reader
.
readLine
())!=
null
)
{
toLineNum
++;
if
(
reader
.
getLineNumber
()
>=
fromLineNum
)
{
logContentBuffer
.
append
(
line
).
append
(
"\n"
);
}
}
return
sb
.
toString
();
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -160,34 +155,40 @@ public class XxlJobFileAppender extends AppenderSkeleton {
...
@@ -160,34 +155,40 @@ public class XxlJobFileAppender extends AppenderSkeleton {
}
}
}
}
}
}
return
null
;
// result
LogResult
logResult
=
new
LogResult
();
logResult
.
setFromLineNum
(
fromLineNum
);
logResult
.
setToLineNum
(
toLineNum
);
logResult
.
setLogContent
(
logContentBuffer
.
toString
());
logResult
.
setEnd
(
false
);
return
logResult
;
/*
// it will return the number of characters actually skipped
reader.skip(Long.MAX_VALUE);
int maxLineNum = reader.getLineNumber();
maxLineNum++; // 最大行号
*/
}
}
/**
/**
* read
data from line num
* read
log data
* @param logFile
* @param logFile
* @param fromLineNum
* @return log line content
* @return log content
* @throws Exception
*/
*/
public
static
String
readLines
From
(
File
logFile
,
int
fromLineNum
)
{
public
static
String
readLines
(
File
logFile
){
LineNumber
Reader
reader
=
null
;
Buffered
Reader
reader
=
null
;
try
{
try
{
reader
=
new
LineNumberReader
(
new
FileReader
(
logFile
));
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
logFile
),
"utf-8"
));
if
(
reader
!=
null
)
{
// sBuffer
StringBuilder
sb
=
new
StringBuilder
();
StringBuffer
sBuffer
=
new
StringBuffer
();
String
line
=
null
;
String
line
=
null
;
int
maxLineNum
=
0
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
while
((
line
=
reader
.
readLine
())!=
null
)
{
sb
.
append
(
line
).
append
(
"\n"
);
maxLineNum
++;
if
(
reader
.
getLineNumber
()
>=
fromLineNum
)
{
sBuffer
.
append
(
line
).
append
(
"\n"
);
}
}
return
sb
.
toString
();
}
}
System
.
out
.
println
(
"maxLineNum : "
+
maxLineNum
);
return
sBuffer
.
toString
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
...
@@ -199,15 +200,7 @@ public class XxlJobFileAppender extends AppenderSkeleton {
...
@@ -199,15 +200,7 @@ public class XxlJobFileAppender extends AppenderSkeleton {
}
}
}
}
}
}
return
null
;
return
null
;
/*
// it will return the number of characters actually skipped
reader.skip(Long.MAX_VALUE);
int maxLineNum = reader.getLineNumber();
maxLineNum++; // 最大行号
*/
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录