Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
aedf603f
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,发现更多精彩内容 >>
提交
aedf603f
编写于
2月 03, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
small refine in HTML codec and consumer
上级
b4e8fcf2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
19 deletion
+49
-19
cat-consumer/src/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
...rc/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
+20
-2
cat-core/src/main/java/com/dianping/cat/message/spi/StringRope.java
...rc/main/java/com/dianping/cat/message/spi/StringRope.java
+11
-5
cat-core/src/main/java/com/dianping/cat/message/spi/codec/HtmlEncodingBufferWriter.java
...nping/cat/message/spi/codec/HtmlEncodingBufferWriter.java
+3
-4
cat-core/src/main/java/com/dianping/cat/message/spi/codec/HtmlMessageCodec.java
.../com/dianping/cat/message/spi/codec/HtmlMessageCodec.java
+10
-5
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
...dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
+2
-1
cat-core/src/test/java/com/dianping/cat/message/spi/codec/HtmlMessageCodecTest.java
.../dianping/cat/message/spi/codec/HtmlMessageCodecTest.java
+3
-2
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
浏览文件 @
aedf603f
...
...
@@ -8,6 +8,7 @@ import java.util.Map;
import
com.dianping.cat.consumer.ip.model.entity.Ip
;
import
com.dianping.cat.consumer.ip.model.entity.IpReport
;
import
com.dianping.cat.consumer.ip.model.entity.Segment
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.message.spi.AbstractMessageAnalyzer
;
...
...
@@ -16,6 +17,8 @@ import com.dianping.cat.message.spi.MessageTree;
public
class
IpAnalyzer
extends
AbstractMessageAnalyzer
<
IpReport
>
{
private
Map
<
String
,
IpReport
>
m_reports
=
new
HashMap
<
String
,
IpReport
>();
private
static
final
String
TOKEN
=
"RemoteIP="
;
private
IpReport
findOrCreateReport
(
String
domain
)
{
IpReport
report
=
m_reports
.
get
(
domain
);
...
...
@@ -58,12 +61,28 @@ public class IpAnalyzer extends AbstractMessageAnalyzer<IpReport> {
private
String
getIpAddress
(
Transaction
root
)
{
List
<
Message
>
children
=
((
Transaction
)
root
).
getChildren
();
for
(
Message
child
:
children
)
{
if
(
child
instanceof
Event
&&
child
.
getType
().
equals
(
"URL"
)
&&
child
.
getName
().
equals
(
"ClientInfo"
))
{
String
data
=
child
.
getData
().
toString
();
int
off
=
data
.
indexOf
(
TOKEN
);
if
(
off
>=
0
)
{
int
pos
=
data
.
indexOf
(
'&'
,
off
+
TOKEN
.
length
());
if
(
pos
>
0
)
{
return
data
.
substring
(
off
+
TOKEN
.
length
(),
pos
);
}
}
break
;
}
}
return
null
;
}
@Override
protected
boolean
isTimeout
()
{
// TODO Auto-generated method stub
return
false
;
}
...
...
@@ -97,5 +116,4 @@ public class IpAnalyzer extends AbstractMessageAnalyzer<IpReport> {
// TODO Auto-generated method stub
}
}
cat-core/src/main/java/com/dianping/cat/message/spi/StringRope.java
浏览文件 @
aedf603f
...
...
@@ -57,13 +57,19 @@ public class StringRope {
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
(
256
);
if
(
m_parts
.
isEmpty
())
{
return
""
;
}
else
if
(
m_parts
.
size
()
==
1
)
{
return
m_parts
.
get
(
0
);
}
else
{
StringBuilder
sb
=
new
StringBuilder
(
256
);
for
(
String
part
:
m_parts
)
{
sb
.
append
(
part
);
}
for
(
String
part
:
m_parts
)
{
sb
.
append
(
part
);
return
sb
.
toString
();
}
return
sb
.
toString
();
}
public
int
writeTo
(
ChannelBuffer
buffer
,
BufferWriter
writer
)
{
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/codec/HtmlEncodingBufferWriter.java
浏览文件 @
aedf603f
...
...
@@ -2,7 +2,6 @@ package com.dianping.cat.message.spi.codec;
import
org.jboss.netty.buffer.ChannelBuffer
;
public
class
HtmlEncodingBufferWriter
implements
BufferWriter
{
private
static
byte
[]
AMP
=
"&"
.
getBytes
();
...
...
@@ -24,17 +23,17 @@ public class HtmlEncodingBufferWriter implements BufferWriter {
if
(
b
==
'&'
)
{
buffer
.
writeBytes
(
data
,
offset
,
i
-
offset
);
buffer
.
writeBytes
(
AMP
);
count
+=
AMP
.
length
;
count
+=
AMP
.
length
-
1
;
offset
=
i
+
1
;
}
else
if
(
b
==
'<'
)
{
buffer
.
writeBytes
(
data
,
offset
,
i
-
offset
);
buffer
.
writeBytes
(
LT
);
count
+=
LT
.
length
;
count
+=
LT
.
length
-
1
;
offset
=
i
+
1
;
}
else
if
(
b
==
'>'
)
{
buffer
.
writeBytes
(
data
,
offset
,
i
-
offset
);
buffer
.
writeBytes
(
GT
);
count
+=
GT
.
length
;
count
+=
GT
.
length
-
1
;
offset
=
i
+
1
;
}
else
if
(
b
==
'\n'
)
{
// we want '\n' be output again for better format
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/codec/HtmlMessageCodec.java
浏览文件 @
aedf603f
...
...
@@ -19,11 +19,14 @@ import com.dianping.cat.message.spi.MessageTree;
import
com.dianping.cat.message.spi.StringRope
;
import
com.site.lookup.annotation.Inject
;
/**
* Local use only, do not use it over network since it only supports one-way encoding
*/
public
class
HtmlMessageCodec
implements
MessageCodec
{
private
static
final
String
ID
=
"HT1"
;
// HTML version 1
@Inject
private
BufferWriter
m_writer
=
new
HtmlEncodingBufferWriter
()
;
private
BufferWriter
m_writer
;
private
BufferHelper
m_bufferHelper
=
new
BufferHelper
(
m_writer
);
...
...
@@ -243,9 +246,10 @@ public class HtmlMessageCodec implements MessageCodec {
count
+=
TD1
.
length
;
}
else
{
String
tag
=
"<td class=\""
+
styleClass
+
"\">"
;
byte
[]
bytes
=
tag
.
getBytes
();
buf
.
writeBytes
(
tag
.
getBytes
()
);
count
+=
tag
.
length
()
;
buf
.
writeBytes
(
bytes
);
count
+=
bytes
.
length
;
}
buf
.
writeBytes
(
data
);
...
...
@@ -273,9 +277,10 @@ public class HtmlMessageCodec implements MessageCodec {
return
TR1
.
length
;
}
else
{
String
tag
=
"<tr class=\""
+
styleClass
+
"\">"
;
byte
[]
bytes
=
tag
.
getBytes
();
buf
.
writeBytes
(
tag
.
getBytes
()
);
return
tag
.
length
()
;
buf
.
writeBytes
(
bytes
);
return
bytes
.
length
;
}
}
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
浏览文件 @
aedf603f
...
...
@@ -38,11 +38,12 @@ public class DumpToHtmlConsumer implements MessageConsumer, Initializable, LogEn
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
(
8192
);
m_codec
.
encode
(
tree
,
buf
);
fos
=
new
FileOutputStream
(
file
);
int
length
=
buf
.
readInt
();
fos
=
new
FileOutputStream
(
file
);
buf
.
getBytes
(
buf
.
readerIndex
(),
fos
,
length
);
buf
.
clear
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
String
.
format
(
"Error when dumping to HTML file(%s)!"
,
file
),
e
);
}
finally
{
...
...
cat-core/src/test/java/com/dianping/cat/message/spi/codec/HtmlMessageCodecTest.java
浏览文件 @
aedf603f
...
...
@@ -24,6 +24,7 @@ public class HtmlMessageCodecTest {
HtmlMessageCodec
codec
=
new
HtmlMessageCodec
();
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
();
codec
.
setBufferWriter
(
new
HtmlEncodingBufferWriter
());
codec
.
encodeMessage
(
message
,
buf
,
0
,
null
);
String
actual
=
buf
.
toString
(
Charset
.
forName
(
"utf-8"
));
...
...
@@ -34,6 +35,7 @@ public class HtmlMessageCodecTest {
HtmlMessageCodec
codec
=
new
HtmlMessageCodec
();
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
();
codec
.
setBufferWriter
(
new
HtmlEncodingBufferWriter
());
codec
.
encode
(
tree
,
buf
);
buf
.
readInt
();
// get rid of length
String
actual
=
buf
.
toString
(
Charset
.
forName
(
"utf-8"
));
...
...
@@ -90,8 +92,7 @@ public class HtmlMessageCodecTest {
long
timestamp
=
1325489621987L
;
Event
event
=
newEvent
(
"type"
,
"name"
,
timestamp
,
"0"
,
"here is the data."
);
check
(
event
,
"<tr><td>E15:33:41.987</td><td>type</td><td>name</td><td>0</td><td>here is the data.</td></tr>\r\n"
);
check
(
event
,
"<tr><td>E15:33:41.987</td><td>type</td><td>name</td><td>0</td><td>here is the data.</td></tr>\r\n"
);
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录