Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
ae26cb0c
提交
ae26cb0c
authored
3月 23, 2017
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
日志rollback展示
上级
049091c4
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
303 行增加
和
93 行删除
+303
-93
qq群-一个xxl同学进了58.png
doc/images/qq群-一个xxl同学进了58.png
+0
-0
JobLogController.java
...n/java/com/xxl/job/admin/controller/JobLogController.java
+30
-30
logdetail.ftl
...min/src/main/webapp/WEB-INF/template/joblog/logdetail.ftl
+95
-6
logdetail.index.1.js
xxl-job-admin/src/main/webapp/static/js/logdetail.index.1.js
+78
-0
ExecutorBiz.java
...-core/src/main/java/com/xxl/job/core/biz/ExecutorBiz.java
+3
-1
ExecutorBizImpl.java
.../main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
+4
-3
LogResult.java
...e/src/main/java/com/xxl/job/core/biz/model/LogResult.java
+47
-0
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;
import
com.xxl.job.admin.dao.IXxlJobInfoDao
;
import
com.xxl.job.admin.dao.IXxlJobLogDao
;
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.rpc.netcom.NetComClientProxy
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -92,43 +93,42 @@ public class JobLogController {
maps
.
put
(
"data"
,
list
);
// 分页列表
return
maps
;
}
@RequestMapping
(
"/logDetail"
)
@ResponseBody
public
ReturnT
<
String
>
logDetail
(
int
id
){
@RequestMapping
(
"/logDetail
Page
"
)
public
String
logDetailPage
(
int
id
,
Model
model
){
// base check
XxlJobLog
log
=
xxlJobLogDao
.
load
(
id
);
if
(
log
==
null
)
{
return
new
ReturnT
<
String
>(
500
,
"查看执行日志失败: 参数异常"
);
}
if
(
ReturnT
.
SUCCESS_CODE
!=
log
.
getTriggerCode
())
{
return
new
ReturnT
<
String
>(
500
,
"查看执行日志失败: 任务发起调度失败,无法查看执行日志"
);
ReturnT
<
String
>
logStatue
=
ReturnT
.
SUCCESS
;
XxlJobLog
jobLog
=
xxlJobLogDao
.
load
(
id
);
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
,
"查看执行日志失败: 任务发起调度失败,无法查看执行日志"
);
}
model
.
addAttribute
(
"executorAddress"
,
jobLog
.
getExecutorAddress
());
model
.
addAttribute
(
"triggerTime"
,
jobLog
.
getTriggerTime
().
getTime
());
model
.
addAttribute
(
"logId"
,
jobLog
.
getId
());
}
// trigger id, trigger time
ExecutorBiz
executorBiz
=
null
;
model
.
addAttribute
(
"logStatue"
,
logStatue
);
return
"joblog/logdetail"
;
}
@RequestMapping
(
"/logDetailCat"
)
@ResponseBody
public
ReturnT
<
LogResult
>
logDetailCat
(
String
executorAddress
,
long
triggerTime
,
int
logId
,
int
fromLineNum
){
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
)
{
e
.
printStackTrace
();
return
new
ReturnT
<
String
>(
500
,
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
());
return
new
ReturnT
<
LogResult
>(
ReturnT
.
FAIL_CODE
,
e
.
getMessage
());
}
}
@RequestMapping
(
"/logDetailPage"
)
public
String
logDetailPage
(
int
id
,
Model
model
){
ReturnT
<
String
>
data
=
logDetail
(
id
);
model
.
addAttribute
(
"result"
,
data
);
return
"joblog/logdetail"
;
}
@RequestMapping
(
"/logKill"
)
@ResponseBody
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;" >
<pre>
<br>
<#if result.code == 200>${result.content}
<#else>${result.msg}</#if>
</pre>
<!DOCTYPE html>
<html>
<head>
<title>
任务调度中心
</title>
<
#
import
"/
common
/
common
.
macro
.
ftl
"
as
netCommon
>
<
@
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>
</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
;
import
com.xxl.job.core.biz.model.LogResult
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.biz.model.TriggerParam
;
...
...
@@ -25,9 +26,10 @@ public interface ExecutorBiz {
* log
* @param logDateTim
* @param logId
* @param fromLineNum
* @return
*/
public
ReturnT
<
String
>
log
(
long
logDateTim
,
int
logId
);
public
ReturnT
<
LogResult
>
log
(
long
logDateTim
,
int
logId
,
int
fromLineNum
);
/**
* run
...
...
xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
浏览文件 @
ae26cb0c
package
com
.
xxl
.
job
.
core
.
biz
.
impl
;
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.TriggerParam
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
...
...
@@ -42,12 +43,12 @@ public class ExecutorBizImpl implements ExecutorBiz {
}
@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
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
logDateTim
),
logId
);
String
logConteng
=
XxlJobFileAppender
.
readLog
(
logFileName
);
return
new
ReturnT
<
String
>(
ReturnT
.
SUCCESS_CODE
,
logConteng
);
LogResult
logResult
=
XxlJobFileAppender
.
readLog
(
logFileName
,
fromLineNum
);
return
new
ReturnT
<
LogResult
>(
logResult
);
}
@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
;
import
com.xxl.job.core.biz.model.LogResult
;
import
org.apache.log4j.AppenderSkeleton
;
import
org.apache.log4j.Layout
;
import
org.apache.log4j.spi.LoggingEvent
;
...
...
@@ -117,8 +118,9 @@ public class XxlJobFileAppender extends AppenderSkeleton {
* @param logFileName
* @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
)
{
return
null
;
}
...
...
@@ -127,27 +129,20 @@ public class XxlJobFileAppender extends AppenderSkeleton {
if
(!
logFile
.
exists
())
{
return
null
;
}
String
logData
=
readLines
(
logFile
);
return
logData
;
}
/**
* read log data
* @param logFile
* @return log line content
*/
public
static
String
readLines
(
File
logFile
){
BufferedReader
reader
=
null
;
// read file
StringBuffer
logContentBuffer
=
new
StringBuffer
();
int
toLineNum
=
0
;
LineNumberReader
reader
=
null
;
try
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
logFile
),
"utf-8"
));
if
(
reader
!=
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
).
append
(
"\n"
);
reader
=
new
LineNumberReader
(
new
FileReader
(
logFile
));
String
line
=
null
;
while
((
line
=
reader
.
readLine
())!=
null
)
{
toLineNum
++;
if
(
reader
.
getLineNumber
()
>=
fromLineNum
)
{
logContentBuffer
.
append
(
line
).
append
(
"\n"
);
}
return
sb
.
toString
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
@@ -159,35 +154,41 @@ public class XxlJobFileAppender extends AppenderSkeleton {
e
.
printStackTrace
();
}
}
}
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 fromLineNum
* @return log content
* @throws Exception
* @return log line content
*/
public
static
String
readLines
From
(
File
logFile
,
int
fromLineNum
)
{
LineNumber
Reader
reader
=
null
;
public
static
String
readLines
(
File
logFile
){
Buffered
Reader
reader
=
null
;
try
{
reader
=
new
LineNumberReader
(
new
FileReader
(
logFile
));
// sBuffer
StringBuffer
sBuffer
=
new
StringBuffer
();
String
line
=
null
;
int
maxLineNum
=
0
;
while
((
line
=
reader
.
readLine
())!=
null
)
{
maxLineNum
++;
if
(
reader
.
getLineNumber
()
>=
fromLineNum
)
{
sBuffer
.
append
(
line
).
append
(
"\n"
);
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
logFile
),
"utf-8"
));
if
(
reader
!=
null
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
).
append
(
"\n"
);
}
return
sb
.
toString
();
}
System
.
out
.
println
(
"maxLineNum : "
+
maxLineNum
);
return
sBuffer
.
toString
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
@@ -198,16 +199,8 @@ public class XxlJobFileAppender extends AppenderSkeleton {
e
.
printStackTrace
();
}
}
}
}
return
null
;
/*
// it will return the number of characters actually skipped
reader.skip(Long.MAX_VALUE);
int maxLineNum = reader.getLineNumber();
maxLineNum++; // 最大行号
*/
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论