Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
bbc8fb39
Commit
bbc8fb39
authored
May 12, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add clog
parent
dc493792
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
LoggingCustomizer.java
...ava/com/ctrip/apollo/biz/customize/LoggingCustomizer.java
+90
-0
pom.xml
pom.xml
+19
-0
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/customize/LoggingCustomizer.java
0 → 100644
View file @
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
View file @
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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment