Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
5904f328
Commit
5904f328
authored
Aug 08, 2019
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增日志端点监控
parent
cecbbe32
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
pom.xml
logger-starter/secoo-log-starter/pom.xml
+6
-0
MatrixLogListenerConfiguration.java
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/config/MatrixLogListenerConfiguration.java
+14
-2
LogEndpoint.java
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/endpoint/LogEndpoint.java
+29
-0
No files found.
logger-starter/secoo-log-starter/pom.xml
View file @
5904f328
...
...
@@ -31,6 +31,11 @@
<artifactId>
apollo-client
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-actuator-autoconfigure
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/config/MatrixLogListenerConfiguration.java
View file @
5904f328
...
...
@@ -5,12 +5,16 @@ import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfig
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener
;
import
com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration
;
import
com.secoo.mall.logs.endpoint.LogEndpoint
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.logging.LogLevel
;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.StringUtils
;
...
...
@@ -19,6 +23,7 @@ import java.util.Set;
/**
* 用于提供动态日志切换
*
* @author qianglu
*/
@Configuration
...
...
@@ -44,11 +49,11 @@ public class MatrixLogListenerConfiguration implements InitializingBean {
private
void
refreshLoggingLevels
()
{
Set
<
String
>
keyNames
=
config
.
getPropertyNames
();
for
(
String
key
:
keyNames
)
{
if
(
StringUtils
.
startsWithIgnoreCase
(
key
,
LOGGER_TAG
))
{
if
(
StringUtils
.
startsWithIgnoreCase
(
key
,
LOGGER_TAG
))
{
String
strLevel
=
config
.
getProperty
(
key
,
"info"
);
LogLevel
level
=
LogLevel
.
valueOf
(
strLevel
.
toUpperCase
());
loggingSystem
.
setLogLevel
(
key
.
replace
(
LOGGER_TAG
,
""
),
level
);
logger
.
info
(
"update class {} logger level to {}"
,
key
,
strLevel
);
logger
.
info
(
"update class {} logger level to {}"
,
key
,
strLevel
);
}
}
}
...
...
@@ -58,4 +63,11 @@ public class MatrixLogListenerConfiguration implements InitializingBean {
public
void
afterPropertiesSet
()
throws
Exception
{
refreshLoggingLevels
();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public
LogEndpoint
logEndpoint
()
{
return
new
LogEndpoint
();
}
}
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/endpoint/LogEndpoint.java
0 → 100644
View file @
5904f328
package
com
.
secoo
.
mall
.
logs
.
endpoint
;
import
ch.qos.logback.classic.Logger
;
import
ch.qos.logback.classic.LoggerContext
;
import
org.slf4j.impl.StaticLoggerBinder
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.ReadOperation
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* @author qianglu
*/
@Endpoint
(
id
=
"matrixlog"
)
public
class
LogEndpoint
{
@ReadOperation
public
List
<
String
>
matrixlog
()
{
List
<
String
>
result
=
new
LinkedList
<>();
LoggerContext
factory
=
(
LoggerContext
)
StaticLoggerBinder
.
getSingleton
().
getLoggerFactory
();
List
<
Logger
>
li
=
factory
.
getLoggerList
();
li
.
forEach
(
logs
->
result
.
add
(
logs
.
getName
()));
return
result
;
}
}
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