Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
b9426e4f
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b9426e4f
编写于
1月 15, 2014
作者:
D
Daniel Beck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-21386] Allow more specific loggers to reduce log level
上级
4ace130e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
115 addition
and
9 deletion
+115
-9
core/src/main/java/hudson/logging/LogRecorder.java
core/src/main/java/hudson/logging/LogRecorder.java
+48
-4
core/src/test/java/hudson/logging/LogRecorderTest.java
core/src/test/java/hudson/logging/LogRecorderTest.java
+64
-2
war/src/main/webapp/help/LogRecorder/logger.html
war/src/main/webapp/help/LogRecorder/logger.html
+3
-3
未找到文件。
core/src/main/java/hudson/logging/LogRecorder.java
浏览文件 @
b9426e4f
...
...
@@ -84,14 +84,38 @@ public class LogRecorder extends AbstractModelObject implements Saveable {
public
final
CopyOnWriteList
<
Target
>
targets
=
new
CopyOnWriteList
<
Target
>();
private
transient
/*almost final*/
RingBufferLogHandler
handler
=
new
RingBufferLogHandler
()
{
@Restricted
(
NoExternalUse
.
class
)
Target
[]
orderedTargets
()
{
// will contain targets ordered by reverse name length (place specific targets at the beginning)
Target
[]
ts
=
targets
.
toArray
(
new
Target
[]{});
Arrays
.
sort
(
ts
,
new
Comparator
<
Target
>()
{
public
int
compare
(
Target
left
,
Target
right
)
{
return
right
.
getName
().
length
()
-
left
.
getName
().
length
();
}
});
return
ts
;
}
@Restricted
(
NoExternalUse
.
class
)
transient
/*almost final*/
RingBufferLogHandler
handler
=
new
RingBufferLogHandler
()
{
@Override
public
void
publish
(
LogRecord
record
)
{
for
(
Target
t
:
targets
)
{
if
(
t
.
includes
(
record
))
{
for
(
Target
t
:
orderedTargets
())
{
Boolean
match
=
t
.
matches
(
record
);
if
(
match
==
null
)
{
// domain does not match, so continue looking
continue
;
}
if
(
match
.
booleanValue
())
{
// most specific logger matches, so publish
super
.
publish
(
record
);
return
;
}
// most specific logger does not match, so don't publish
// allows reducing log level for more specific loggers
return
;
}
}
};
...
...
@@ -123,6 +147,11 @@ public class LogRecorder extends AbstractModelObject implements Saveable {
return
Level
.
parse
(
String
.
valueOf
(
level
));
}
public
String
getName
()
{
return
name
;
}
@Deprecated
public
boolean
includes
(
LogRecord
r
)
{
if
(
r
.
getLevel
().
intValue
()
<
level
)
return
false
;
// below the threshold
...
...
@@ -136,6 +165,21 @@ public class LogRecorder extends AbstractModelObject implements Saveable {
return
rest
.
startsWith
(
"."
)
||
rest
.
length
()==
0
;
}
public
Boolean
matches
(
LogRecord
r
)
{
boolean
levelSufficient
=
r
.
getLevel
().
intValue
()
>=
level
;
if
(
name
.
length
()
==
0
)
{
return
Boolean
.
valueOf
(
levelSufficient
);
// include if level matches
}
String
logName
=
r
.
getLoggerName
();
if
(
logName
==
null
||
!
logName
.
startsWith
(
name
))
return
null
;
// not in the domain of this logger
String
rest
=
logName
.
substring
(
name
.
length
());
if
(
rest
.
startsWith
(
"."
)
||
rest
.
length
()==
0
)
{
return
Boolean
.
valueOf
(
levelSufficient
);
// include if level matches
}
return
null
;
}
public
Logger
getLogger
()
{
if
(
logger
==
null
)
{
logger
=
Logger
.
getLogger
(
name
);
...
...
core/src/test/java/hudson/logging/LogRecorderTest.java
浏览文件 @
b9426e4f
...
...
@@ -42,10 +42,72 @@ public class LogRecorderTest {
assertTrue
(
includes
(
""
,
"hudson.model.Hudson"
));
}
private
static
boolean
includes
(
String
target
,
String
logger
)
{
LogRecord
r
=
new
LogRecord
(
Level
.
INFO
,
"whatever"
);
@Test
public
void
targetMatches
()
{
assertTrue
(
matches
(
"hudson"
,
"hudson"
));
assertFalse
(
matches
(
"hudson"
,
"hudson"
,
Level
.
FINE
));
assertNull
(
matches
(
"hudson"
,
"hudsone"
));
assertNull
(
matches
(
"hudson"
,
"hudso"
));
assertTrue
(
matches
(
"hudson"
,
"hudson.model.Hudson"
));
assertFalse
(
matches
(
"hudson"
,
"hudson.model.Hudson"
,
Level
.
FINE
));
assertNull
(
matches
(
"hudson"
,
"jenkins.model.Jenkins"
));
assertTrue
(
matches
(
""
,
"hudson.model.Hudson"
));
assertFalse
(
matches
(
""
,
"hudson.model.Hudson"
,
Level
.
FINE
));
}
@Test
public
void
testSpecificExclusion
()
{
LogRecorder
lr
=
new
LogRecorder
(
"foo"
);
LogRecorder
.
Target
targetLevel0
=
new
LogRecorder
.
Target
(
""
,
Level
.
FINE
);
LogRecorder
.
Target
targetLevel1
=
new
LogRecorder
.
Target
(
"foo"
,
Level
.
INFO
);
LogRecorder
.
Target
targetLevel2
=
new
LogRecorder
.
Target
(
"foo.bar"
,
Level
.
SEVERE
);
lr
.
targets
.
add
(
targetLevel1
);
lr
.
targets
.
add
(
targetLevel2
);
lr
.
targets
.
add
(
targetLevel0
);
assertEquals
(
lr
.
orderedTargets
()[
0
],
targetLevel2
);
assertEquals
(
lr
.
orderedTargets
()[
1
],
targetLevel1
);
assertEquals
(
lr
.
orderedTargets
()[
2
],
targetLevel0
);
LogRecord
r1
=
createLogRecord
(
"baz"
,
Level
.
INFO
,
"visible"
);
LogRecord
r2
=
createLogRecord
(
"foo"
,
Level
.
FINE
,
"hidden"
);
LogRecord
r3
=
createLogRecord
(
"foo.bar"
,
Level
.
INFO
,
"hidden"
);
LogRecord
r4
=
createLogRecord
(
"foo.bar.baz"
,
Level
.
INFO
,
"hidden"
);
LogRecord
r5
=
createLogRecord
(
"foo.bar.baz"
,
Level
.
SEVERE
,
"visible"
);
LogRecord
r6
=
createLogRecord
(
"foo"
,
Level
.
INFO
,
"visible"
);
lr
.
handler
.
publish
(
r1
);
lr
.
handler
.
publish
(
r2
);
lr
.
handler
.
publish
(
r3
);
lr
.
handler
.
publish
(
r4
);
lr
.
handler
.
publish
(
r5
);
lr
.
handler
.
publish
(
r6
);
assertTrue
(
lr
.
handler
.
getView
().
contains
(
r1
));
assertFalse
(
lr
.
handler
.
getView
().
contains
(
r2
));
assertFalse
(
lr
.
handler
.
getView
().
contains
(
r3
));
assertFalse
(
lr
.
handler
.
getView
().
contains
(
r4
));
assertTrue
(
lr
.
handler
.
getView
().
contains
(
r5
));
assertTrue
(
lr
.
handler
.
getView
().
contains
(
r6
));
}
private
static
LogRecord
createLogRecord
(
String
logger
,
Level
level
,
String
message
)
{
LogRecord
r
=
new
LogRecord
(
level
,
message
);
r
.
setLoggerName
(
logger
);
return
r
;
}
private
static
boolean
includes
(
String
target
,
String
logger
)
{
LogRecord
r
=
createLogRecord
(
logger
,
Level
.
INFO
,
"whatever"
);
return
new
LogRecorder
.
Target
(
target
,
Level
.
INFO
).
includes
(
r
);
}
private
static
Boolean
matches
(
String
target
,
String
logger
)
{
return
matches
(
target
,
logger
,
Level
.
INFO
);
}
private
static
Boolean
matches
(
String
target
,
String
logger
,
Level
loggerLevel
)
{
LogRecord
r
=
createLogRecord
(
logger
,
loggerLevel
,
"whatever"
);
return
new
LogRecorder
.
Target
(
target
,
Level
.
INFO
).
matches
(
r
);
}
}
war/src/main/webapp/help/LogRecorder/logger.html
浏览文件 @
b9426e4f
...
...
@@ -3,11 +3,11 @@
this log recorder will collect. For example, if you specify
<tt>
hudson.model.Hudson
</tt>
and
<tt>
info
</tt>
, any logs recorded
for
<tt>
hudson.model.Hudson
</tt>
or its descendants with the log level
info or above will show up in this log recorder.
info or above will show up in this log recorder, unless a more specific
logger with higher log level is also specific.
<p>
If you have multiple entries, a log entry that matches any of them
will be collected.
If you have multiple entries, a log entry will the most specific one will be collected.
<p>
Also see
<a
href=
"http://wiki.jenkins-ci.org/display/JENKINS/Logger+Configuration"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录