Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
82a14c4e
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
82a14c4e
编写于
7月 13, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix another bug within log4j appender
上级
347a538d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
68 addition
and
11 deletion
+68
-11
cat-core/src/main/java/com/dianping/cat/log4j/CatAppender.java
...ore/src/main/java/com/dianping/cat/log4j/CatAppender.java
+16
-6
cat-core/src/test/java/com/dianping/cat/AllTests.java
cat-core/src/test/java/com/dianping/cat/AllTests.java
+11
-5
cat-core/src/test/java/com/dianping/cat/log4j/CatAppenderTest.java
...src/test/java/com/dianping/cat/log4j/CatAppenderTest.java
+41
-0
未找到文件。
cat-core/src/main/java/com/dianping/cat/log4j/CatAppender.java
浏览文件 @
82a14c4e
...
...
@@ -6,6 +6,10 @@ import org.apache.log4j.spi.LoggingEvent;
import
org.apache.log4j.spi.ThrowableInformation
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.MessageProducer
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.message.spi.MessageTree
;
public
class
CatAppender
extends
AppenderSkeleton
{
@Override
...
...
@@ -14,12 +18,18 @@ public class CatAppender extends AppenderSkeleton {
ThrowableInformation
throwableInformation
=
event
.
getThrowableInformation
();
if
(
throwableInformation
!=
null
)
{
if
(
Cat
.
getManager
().
getThreadLocalMessageTree
()
!=
null
)
{
Cat
.
getProducer
().
logError
(
throwableInformation
.
getThrowable
());
// } else {
// Cat.setup(null);
// Cat.getProducer().logError(throwableInformation.getThrowable());
// Cat.reset();
MessageProducer
cat
=
Cat
.
getProducer
();
Throwable
exception
=
throwableInformation
.
getThrowable
();
MessageTree
tree
=
Cat
.
getManager
().
getThreadLocalMessageTree
();
if
(
tree
==
null
)
{
Transaction
t
=
cat
.
newTransaction
(
"System"
,
"Log4jException"
);
cat
.
logError
(
exception
);
t
.
setStatus
(
Message
.
SUCCESS
);
t
.
complete
();
}
else
{
cat
.
logError
(
exception
);
}
}
}
...
...
cat-core/src/test/java/com/dianping/cat/
message/
AllTests.java
→
cat-core/src/test/java/com/dianping/cat/AllTests.java
浏览文件 @
82a14c4e
package
com.dianping.cat
.message
;
package
com.dianping.cat
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
com.dianping.cat.CatTest
;
import
com.dianping.cat.log4j.CatAppenderTest
;
import
com.dianping.cat.message.EventTest
;
import
com.dianping.cat.message.HeartbeatTest
;
import
com.dianping.cat.message.TransactionTest
;
import
com.dianping.cat.message.configuration.ClientConfigTest
;
import
com.dianping.cat.message.internal.MessageIdFactoryTest
;
import
com.dianping.cat.message.internal.MillisSecondTimerTest
;
...
...
@@ -19,9 +22,14 @@ import com.dianping.cat.storage.report.LocalReportBucketTest;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
CatTest
.
class
,
/* <default> */
CatTest
.
class
,
/* .log4j */
CatAppenderTest
.
class
,
/* .message */
EventTest
.
class
,
HeartbeatTest
.
class
,
...
...
@@ -34,8 +42,6 @@ ClientConfigTest.class,
/* .internal */
MessageIdFactoryTest
.
class
,
//MessageProducerTest.class,
MillisSecondTimerTest
.
class
,
/* .io */
...
...
cat-core/src/test/java/com/dianping/cat/log4j/CatAppenderTest.java
0 → 100644
浏览文件 @
82a14c4e
package
com.dianping.cat.log4j
;
import
org.apache.log4j.Category
;
import
org.apache.log4j.Level
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.spi.LoggingEvent
;
import
org.junit.Test
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
public
class
CatAppenderTest
{
@Test
public
void
testWithTransaction
()
throws
InterruptedException
{
CatAppender
appender
=
new
CatAppender
();
Throwable
throwable
=
new
Exception
();
Category
logger
=
Logger
.
getLogger
(
CatAppenderTest
.
class
);
LoggingEvent
event
=
new
LoggingEvent
(
"test"
,
logger
,
Level
.
ERROR
,
null
,
throwable
);
Transaction
t
=
Cat
.
getProducer
().
newTransaction
(
"Test"
,
"test"
);
appender
.
append
(
event
);
t
.
setStatus
(
Message
.
SUCCESS
);
t
.
complete
();
Thread
.
sleep
(
20
);
}
@Test
public
void
testWithoutTransaction
()
throws
InterruptedException
{
CatAppender
appender
=
new
CatAppender
();
Throwable
throwable
=
new
Exception
();
Category
logger
=
Logger
.
getLogger
(
CatAppenderTest
.
class
);
LoggingEvent
event
=
new
LoggingEvent
(
"test"
,
logger
,
Level
.
ERROR
,
null
,
throwable
);
appender
.
append
(
event
);
Thread
.
sleep
(
10
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录