Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
bbc8fb39
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bbc8fb39
编写于
5月 12, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add clog
上级
dc493792
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
109 addition
and
0 deletion
+109
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/customize/LoggingCustomizer.java
...ava/com/ctrip/apollo/biz/customize/LoggingCustomizer.java
+90
-0
pom.xml
pom.xml
+19
-0
未找到文件。
apollo-biz/src/main/java/com/ctrip/apollo/biz/customize/LoggingCustomizer.java
0 → 100644
浏览文件 @
bbc8fb39
package
com.ctrip.apollo.biz.customize
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.biz.entity.ServerConfig
;
import
com.ctrip.apollo.biz.repository.ServerConfigRepository
;
import
com.ctrip.framework.foundation.Foundation
;
import
com.dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
import
java.util.Objects
;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.core.Appender
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Component
public
class
LoggingCustomizer
implements
InitializingBean
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LoggingCustomizer
.
class
);
private
static
final
String
cLoggingAppenderClass
=
"com.ctrip.framework.clogging.agent.appender.CLoggingAppender"
;
private
static
boolean
cLoggingAppenderPresent
=
ClassUtils
.
isPresent
(
cLoggingAppenderClass
,
LoggingCustomizer
.
class
.
getClassLoader
());
private
static
final
String
CLOGGING_SERVER_URL_KEY
=
"clogging.server.url"
;
private
static
final
String
CLOGGING_SERVER_PORT_KEY
=
"clogging.server.port"
;
@Autowired
private
ServerConfigRepository
serverConfigRepository
;
@Override
public
void
afterPropertiesSet
()
{
if
(!
cLoggingAppenderPresent
)
{
return
;
}
try
{
tryConfigCLogging
();
}
catch
(
Throwable
ex
)
{
logger
.
error
(
"Config CLogging failed"
,
ex
);
Cat
.
logError
(
ex
);
}
}
private
void
tryConfigCLogging
()
throws
Exception
{
String
appId
=
Foundation
.
app
().
getAppId
();
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
logger
.
warn
(
"App id is null or empty!"
);
return
;
}
ServerConfig
cloggingUrl
=
serverConfigRepository
.
findByKey
(
CLOGGING_SERVER_URL_KEY
);
ServerConfig
cloggingPort
=
serverConfigRepository
.
findByKey
(
CLOGGING_SERVER_PORT_KEY
);
if
(
Objects
.
isNull
(
cloggingUrl
)
||
Objects
.
isNull
(
cloggingPort
))
{
logger
.
warn
(
"CLogging config is not set!"
);
return
;
}
LoggerContext
loggerContext
=
(
LoggerContext
)
LoggerFactory
.
getILoggerFactory
();
Class
clazz
=
Class
.
forName
(
cLoggingAppenderClass
);
Appender
cLoggingAppender
=
(
Appender
)
clazz
.
newInstance
();
ReflectionUtils
.
findMethod
(
clazz
,
"setAppId"
,
String
.
class
).
invoke
(
cLoggingAppender
,
appId
);
ReflectionUtils
.
findMethod
(
clazz
,
"setServerIp"
,
String
.
class
)
.
invoke
(
cLoggingAppender
,
cloggingUrl
.
getValue
());
ReflectionUtils
.
findMethod
(
clazz
,
"setServerPort"
,
int
.
class
)
.
invoke
(
cLoggingAppender
,
Integer
.
parseInt
(
cloggingPort
.
getValue
()));
cLoggingAppender
.
setName
(
"CentralLogging"
);
cLoggingAppender
.
setContext
(
loggerContext
);
cLoggingAppender
.
start
();
ch
.
qos
.
logback
.
classic
.
Logger
logger
=
(
ch
.
qos
.
logback
.
classic
.
Logger
)
LoggerFactory
.
getLogger
(
"root"
);
logger
.
addAppender
(
cLoggingAppender
);
}
}
pom.xml
浏览文件 @
bbc8fb39
...
...
@@ -145,6 +145,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
com.ctrip.framework.clogging
</groupId>
<artifactId>
clogging-agent
</artifactId>
<version>
3.5.2
</version>
<exclusions>
<exclusion>
<artifactId>
logback-core
</artifactId>
<groupId>
ch.qos.logback
</groupId>
</exclusion>
<exclusion>
<artifactId>
logback-classic
</artifactId>
<groupId>
ch.qos.logback
</groupId>
</exclusion>
</exclusions>
</dependency>
<!--third party -->
<dependency>
<groupId>
mysql
</groupId>
...
...
@@ -411,6 +426,10 @@
<groupId>
com.ctrip.platform
</groupId>
<artifactId>
ctrip-dal-client
</artifactId>
</dependency>
<dependency>
<groupId>
com.ctrip.framework.clogging
</groupId>
<artifactId>
clogging-agent
</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录