Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
a6fbf769
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,发现更多精彩内容 >>
提交
a6fbf769
编写于
1月 13, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add MessageStorage
上级
75456a7f
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
433 addition
and
25 deletion
+433
-25
cat-core/src/main/java/com/dianping/cat/configuration/ComponentsConfigurator.java
...om/dianping/cat/configuration/ComponentsConfigurator.java
+5
-0
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
.../dianping/cat/message/internal/DefaultMessageManager.java
+2
-1
cat-core/src/main/java/com/dianping/cat/message/spi/MessagePathBuilder.java
...java/com/dianping/cat/message/spi/MessagePathBuilder.java
+4
-2
cat-core/src/main/java/com/dianping/cat/message/spi/MessageStorage.java
...ain/java/com/dianping/cat/message/spi/MessageStorage.java
+19
-0
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
...dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
+4
-4
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessagePathBuilder.java
...g/cat/message/spi/internal/DefaultMessagePathBuilder.java
+6
-17
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessageStorage.java
...nping/cat/message/spi/internal/DefaultMessageStorage.java
+70
-0
cat-core/src/main/resources/META-INF/dal/model/model.xml
cat-core/src/main/resources/META-INF/dal/model/model.xml
+1
-1
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+14
-0
cat-home/src/test/intg/com/dianping/cat/AllAllTests.java
cat-home/src/test/intg/com/dianping/cat/AllAllTests.java
+17
-0
java_formatter.xml
java_formatter.xml
+291
-0
未找到文件。
cat-core/src/main/java/com/dianping/cat/configuration/ComponentsConfigurator.java
浏览文件 @
a6fbf769
...
@@ -21,6 +21,7 @@ import com.dianping.cat.message.spi.MessageConsumerRegistry;
...
@@ -21,6 +21,7 @@ import com.dianping.cat.message.spi.MessageConsumerRegistry;
import
com.dianping.cat.message.spi.MessageHandler
;
import
com.dianping.cat.message.spi.MessageHandler
;
import
com.dianping.cat.message.spi.MessageManager
;
import
com.dianping.cat.message.spi.MessageManager
;
import
com.dianping.cat.message.spi.MessagePathBuilder
;
import
com.dianping.cat.message.spi.MessagePathBuilder
;
import
com.dianping.cat.message.spi.MessageStorage
;
import
com.dianping.cat.message.spi.codec.BufferWriter
;
import
com.dianping.cat.message.spi.codec.BufferWriter
;
import
com.dianping.cat.message.spi.codec.EscapingBufferWriter
;
import
com.dianping.cat.message.spi.codec.EscapingBufferWriter
;
import
com.dianping.cat.message.spi.codec.HtmlEncodingBufferWriter
;
import
com.dianping.cat.message.spi.codec.HtmlEncodingBufferWriter
;
...
@@ -31,6 +32,7 @@ import com.dianping.cat.message.spi.consumer.DumpToHtmlConsumer;
...
@@ -31,6 +32,7 @@ import com.dianping.cat.message.spi.consumer.DumpToHtmlConsumer;
import
com.dianping.cat.message.spi.internal.DefaultMessageConsumerRegistry
;
import
com.dianping.cat.message.spi.internal.DefaultMessageConsumerRegistry
;
import
com.dianping.cat.message.spi.internal.DefaultMessageHandler
;
import
com.dianping.cat.message.spi.internal.DefaultMessageHandler
;
import
com.dianping.cat.message.spi.internal.DefaultMessagePathBuilder
;
import
com.dianping.cat.message.spi.internal.DefaultMessagePathBuilder
;
import
com.dianping.cat.message.spi.internal.DefaultMessageStorage
;
import
com.site.lookup.configuration.AbstractResourceConfigurator
;
import
com.site.lookup.configuration.AbstractResourceConfigurator
;
import
com.site.lookup.configuration.Component
;
import
com.site.lookup.configuration.Component
;
...
@@ -50,6 +52,9 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
...
@@ -50,6 +52,9 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
.
req
(
MessageManager
.
class
));
.
req
(
MessageManager
.
class
));
all
.
add
(
C
(
MessagePathBuilder
.
class
,
DefaultMessagePathBuilder
.
class
)
//
all
.
add
(
C
(
MessagePathBuilder
.
class
,
DefaultMessagePathBuilder
.
class
)
//
.
req
(
MessageManager
.
class
));
.
req
(
MessageManager
.
class
));
all
.
add
(
C
(
MessageStorage
.
class
,
"html"
,
DefaultMessageStorage
.
class
)
//
.
req
(
MessagePathBuilder
.
class
)
//
.
req
(
MessageCodec
.
class
,
"html-encode"
));
all
.
add
(
C
(
BufferWriter
.
class
,
"escape"
,
EscapingBufferWriter
.
class
));
all
.
add
(
C
(
BufferWriter
.
class
,
"escape"
,
EscapingBufferWriter
.
class
));
all
.
add
(
C
(
BufferWriter
.
class
,
"html-encode"
,
HtmlEncodingBufferWriter
.
class
));
all
.
add
(
C
(
BufferWriter
.
class
,
"html-encode"
,
HtmlEncodingBufferWriter
.
class
));
...
...
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
浏览文件 @
a6fbf769
...
@@ -3,6 +3,7 @@ package com.dianping.cat.message.internal;
...
@@ -3,6 +3,7 @@ package com.dianping.cat.message.internal;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.Stack
;
import
java.util.Stack
;
import
java.util.UUID
;
import
com.dianping.cat.configuration.model.entity.Config
;
import
com.dianping.cat.configuration.model.entity.Config
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Message
;
...
@@ -128,7 +129,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
...
@@ -128,7 +129,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
m_tree
.
setThreadId
(
Long
.
toHexString
(
Thread
.
currentThread
().
getId
()));
m_tree
.
setThreadId
(
Long
.
toHexString
(
Thread
.
currentThread
().
getId
()));
m_tree
.
setHostName
(
hostName
);
m_tree
.
setHostName
(
hostName
);
m_tree
.
setIpAddress
(
ipAddress
);
m_tree
.
setIpAddress
(
ipAddress
);
m_tree
.
setMessageId
(
"?"
);
// TODO
m_tree
.
setMessageId
(
UUID
.
randomUUID
().
toString
());
// TODO optimize it to shorter UUID
}
}
public
void
add
(
DefaultMessageManager
manager
,
Message
message
)
{
public
void
add
(
DefaultMessageManager
manager
,
Message
message
)
{
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/MessagePathBuilder.java
浏览文件 @
a6fbf769
...
@@ -4,7 +4,9 @@ import java.io.File;
...
@@ -4,7 +4,9 @@ import java.io.File;
import
java.net.URL
;
import
java.net.URL
;
public
interface
MessagePathBuilder
{
public
interface
MessagePathBuilder
{
public
URL
getLogViewUrl
(
MessageTree
tree
);
public
File
getLogViewBaseDir
(
);
public
File
getLogViewFile
(
MessageTree
tree
);
public
URL
getLogViewBaseUrl
();
public
String
getLogViewPath
(
MessageTree
tree
);
}
}
cat-core/src/main/java/com/dianping/cat/message/spi/MessageStorage.java
0 → 100644
浏览文件 @
a6fbf769
package
com.dianping.cat.message.spi
;
import
java.io.File
;
import
java.net.URL
;
public
interface
MessageStorage
{
public
File
getBaseDir
();
public
URL
getBaseUrl
();
/**
* Store a message tree to the storage.
*
* @param tree
* message tree to store
* @return relative path to base directory or base URL
*/
public
String
store
(
MessageTree
tree
);
}
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
浏览文件 @
a6fbf769
...
@@ -18,15 +18,16 @@ public class DumpToHtmlConsumer implements MessageConsumer {
...
@@ -18,15 +18,16 @@ public class DumpToHtmlConsumer implements MessageConsumer {
private
MessageCodec
m_codec
;
private
MessageCodec
m_codec
;
@Inject
@Inject
private
MessagePathBuilder
m_
pathB
uilder
;
private
MessagePathBuilder
m_
b
uilder
;
@Override
@Override
public
void
consume
(
MessageTree
tree
)
{
public
void
consume
(
MessageTree
tree
)
{
File
file
=
m_pathBuilder
.
getLogViewFile
(
tree
);
File
baseDir
=
m_builder
.
getLogViewBaseDir
();
File
file
=
new
File
(
baseDir
,
m_builder
.
getLogViewPath
(
tree
));
FileOutputStream
fos
=
null
;
FileOutputStream
fos
=
null
;
try
{
try
{
ChannelBuffer
buf
=
ChannelBuffers
.
b
uffer
(
8192
);
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicB
uffer
(
8192
);
m_codec
.
encode
(
tree
,
buf
);
m_codec
.
encode
(
tree
,
buf
);
fos
=
new
FileOutputStream
(
file
);
fos
=
new
FileOutputStream
(
file
);
...
@@ -42,7 +43,6 @@ public class DumpToHtmlConsumer implements MessageConsumer {
...
@@ -42,7 +43,6 @@ public class DumpToHtmlConsumer implements MessageConsumer {
}
}
}
}
}
}
}
}
@Override
@Override
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessagePathBuilder.java
浏览文件 @
a6fbf769
...
@@ -24,28 +24,17 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
...
@@ -24,28 +24,17 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
private
URL
m_baseLogUrl
;
private
URL
m_baseLogUrl
;
@Override
@Override
public
File
getLogViewFile
(
MessageTree
tree
)
{
public
File
getLogViewBaseDir
()
{
String
relativePath
=
getRelativePath
(
tree
);
return
m_baseLogDir
;
File
file
=
new
File
(
m_baseLogDir
,
relativePath
);
return
file
;
}
}
@Override
@Override
public
URL
getLogViewUrl
(
MessageTree
tree
)
{
public
URL
getLogViewBaseUrl
()
{
String
relativePath
=
getRelativePath
(
tree
);
return
m_baseLogUrl
;
try
{
URL
url
=
new
URL
(
m_baseLogUrl
,
relativePath
);
return
url
;
}
catch
(
MalformedURLException
e
)
{
throw
new
RuntimeException
(
String
.
format
(
"Unable to construct message URL(%s, %s)!"
,
m_baseLogUrl
,
relativePath
),
e
);
}
}
}
private
String
getRelativePath
(
MessageTree
tree
)
{
@Override
public
String
getLogViewPath
(
MessageTree
tree
)
{
MessageFormat
format
=
new
MessageFormat
(
"{0,date,yyyyMMdd}/{1}/{2}"
);
MessageFormat
format
=
new
MessageFormat
(
"{0,date,yyyyMMdd}/{1}/{2}"
);
Date
date
=
new
Date
(
tree
.
getMessage
().
getTimestamp
());
Date
date
=
new
Date
(
tree
.
getMessage
().
getTimestamp
());
String
path
=
format
.
format
(
new
Object
[]
{
date
,
tree
.
getDomain
(),
tree
.
getMessageId
()
});
String
path
=
format
.
format
(
new
Object
[]
{
date
,
tree
.
getDomain
(),
tree
.
getMessageId
()
});
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessageStorage.java
0 → 100644
浏览文件 @
a6fbf769
package
com.dianping.cat.message.spi.internal
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.net.URL
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.jboss.netty.buffer.ChannelBuffer
;
import
org.jboss.netty.buffer.ChannelBuffers
;
import
com.dianping.cat.message.spi.MessageCodec
;
import
com.dianping.cat.message.spi.MessagePathBuilder
;
import
com.dianping.cat.message.spi.MessageStorage
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.site.lookup.annotation.Inject
;
public
class
DefaultMessageStorage
implements
MessageStorage
,
LogEnabled
{
@Inject
private
MessagePathBuilder
m_builder
;
@Inject
private
MessageCodec
m_codec
;
private
Logger
m_logger
;
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
File
getBaseDir
()
{
return
m_builder
.
getLogViewBaseDir
();
}
@Override
public
URL
getBaseUrl
()
{
return
m_builder
.
getLogViewBaseUrl
();
}
@Override
public
String
store
(
MessageTree
tree
)
{
String
path
=
m_builder
.
getLogViewPath
(
tree
);
File
file
=
new
File
(
m_builder
.
getLogViewBaseDir
(),
path
);
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
(
8192
);
FileOutputStream
fos
=
null
;
file
.
getParentFile
().
mkdirs
();
try
{
m_codec
.
encode
(
tree
,
buf
);
fos
=
new
FileOutputStream
(
file
);
buf
.
getBytes
(
buf
.
readerIndex
(),
fos
,
buf
.
readableBytes
());
}
catch
(
IOException
e
)
{
m_logger
.
error
(
String
.
format
(
"Error when writing to file(%s)!"
,
file
),
e
);
}
finally
{
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e
)
{
// ignore it
}
}
}
return
path
;
}
}
cat-core/src/main/resources/META-INF/dal/model/model.xml
浏览文件 @
a6fbf769
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
enable-xml-schema=
"true"
enable-xml-sample=
"true"
>
enable-xml-schema=
"true"
enable-xml-sample=
"true"
>
<entity
name=
"config"
root=
"true"
>
<entity
name=
"config"
root=
"true"
>
<attribute
name=
"mode"
required=
"true"
/>
<attribute
name=
"mode"
required=
"true"
/>
<attribute
name=
"base-log-dir"
default-value=
"
.
/catlog"
/>
<attribute
name=
"base-log-dir"
default-value=
"
target
/catlog"
/>
<entity-ref
name=
"property"
type=
"map"
/>
<entity-ref
name=
"property"
type=
"map"
/>
</entity>
</entity>
<entity
name=
"app"
>
<entity
name=
"app"
>
...
...
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
a6fbf769
...
@@ -46,6 +46,20 @@
...
@@ -46,6 +46,20 @@
</requirement>
</requirement>
</requirements>
</requirements>
</component>
</component>
<component>
<role>
com.dianping.cat.message.spi.MessageStorage
</role>
<role-hint>
html
</role-hint>
<implementation>
com.dianping.cat.message.spi.internal.DefaultMessageStorage
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessagePathBuilder
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.message.spi.MessageCodec
</role>
<role-hint>
html-encode
</role-hint>
</requirement>
</requirements>
</component>
<component>
<component>
<role>
com.dianping.cat.message.spi.codec.BufferWriter
</role>
<role>
com.dianping.cat.message.spi.codec.BufferWriter
</role>
<role-hint>
escape
</role-hint>
<role-hint>
escape
</role-hint>
...
...
cat-home/src/test/intg/com/dianping/cat/AllAllTests.java
0 → 100644
浏览文件 @
a6fbf769
package
com.dianping.cat
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
com
.
dianping
.
cat
.
message
.
AllTests
.
class
,
com
.
dianping
.
cat
.
consumer
.
AllTests
.
class
,
})
public
class
AllAllTests
{
}
java_formatter.xml
0 → 100644
浏览文件 @
a6fbf769
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录