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
e9eec4b4
Commit
e9eec4b4
authored
Aug 07, 2019
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增日志级别动态变更
parent
837337c6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
20 deletions
+93
-20
pom.xml
logger-starter/secoo-log-starter/pom.xml
+10
-9
MatrixLogListenerConfiguration.java
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/config/MatrixLogListenerConfiguration.java
+69
-0
spring.factories
logger-starter/secoo-log-starter/src/main/resources/META-INF/spring.factories
+4
-0
logback-secoo.xml
logger-starter/secoo-log-starter/src/main/resources/logback-secoo.xml
+10
-11
No files found.
logger-starter/secoo-log-starter/pom.xml
View file @
e9eec4b4
...
...
@@ -13,15 +13,10 @@
<name>
${project.artifactId}
</name>
<dependencies>
<!-- <!– 桥接slf4j –>-->
<!-- <dependency>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>jcl-over-slf4j</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>log4j-over-slf4j</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<!-- 打印skywalking tid插件-->
<dependency>
<groupId>
org.apache.skywalking
</groupId>
...
...
@@ -31,6 +26,11 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</dependency>
<dependency>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo-client
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
logger-starter/secoo-log-starter/src/main/java/com/secoo/mall/logs/config/MatrixLogListenerConfiguration.java
0 → 100644
View file @
e9eec4b4
package
com
.
secoo
.
mall
.
logs
.
config
;
import
com.ctrip.framework.apollo.Config
;
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
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.logging.LogLevel
;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.util.Set
;
/**
* @author qianglu
*/
@Configuration
@ConditionalOnClass
(
ApolloAutoConfiguration
.
class
)
public
class
MatrixLogListenerConfiguration
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MatrixLogListenerConfiguration
.
class
);
private
static
final
String
LOGGER_TAG
=
"matrix.loggers."
;
@Resource
private
LoggingSystem
loggingSystem
;
@ApolloConfig
private
Config
config
;
@ApolloConfigChangeListener
private
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
refreshLoggingLevels
();
}
@PostConstruct
private
void
refreshLoggingLevels
()
{
Set
<
String
>
keyNames
=
config
.
getPropertyNames
();
for
(
String
key
:
keyNames
)
{
if
(
containsIgnoreCase
(
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
);
}
}
}
private
static
boolean
containsIgnoreCase
(
String
str
,
String
searchStr
)
{
if
(
StringUtils
.
isEmpty
(
str
)
||
StringUtils
.
isEmpty
(
searchStr
))
{
return
false
;
}
int
len
=
searchStr
.
length
();
int
max
=
str
.
length
()
-
len
;
for
(
int
i
=
0
;
i
<=
max
;
i
++)
{
if
(
str
.
regionMatches
(
true
,
i
,
searchStr
,
0
,
len
))
{
return
true
;
}
}
return
false
;
}
}
logger-starter/secoo-log-starter/src/main/resources/META-INF/spring.factories
0 → 100755
View file @
e9eec4b4
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.mall.logs.config.MatrixLogListenerConfiguration
\ No newline at end of file
logger-starter/secoo-log-starter/src/main/resources/logback-s
pring
.xml
→
logger-starter/secoo-log-starter/src/main/resources/logback-s
ecoo
.xml
View file @
e9eec4b4
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd"> -->
<configuration
scan=
"true"
scanPeriod=
"60 seconds"
debug=
"false"
>
<springProperty
scope=
"context"
name=
"
logName
"
source=
"spring.application.name"
defaultValue=
"app"
/>
<springProperty
scope=
"context"
name=
"
logLevel
"
source=
"log.level"
defaultValue=
"info"
/>
<springProperty
scope=
"context"
name=
"
LOG_NAME
"
source=
"spring.application.name"
defaultValue=
"app"
/>
<springProperty
scope=
"context"
name=
"
LOG_LEVEL
"
source=
"log.level"
defaultValue=
"info"
/>
<springProperty
scope=
"context"
name=
"LOG_PATH"
source=
"log.path"
defaultValue=
"/data/logs"
/>
<springProperty
scope=
"context"
name=
"MAX_FILE_SIZE"
source=
"log.max_file_size"
defaultValue=
"128MB"
/>
<springProperty
scope=
"context"
name=
"MAX_HISTORY"
source=
"log.max_history"
defaultValue=
"7"
/>
<springProperty
scope=
"context"
name=
"PATTERN"
source=
"log.pattern"
defaultValue=
"-|%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%X{tid}|%thread|%logger{36}.%M:%L-%msg%n"
/>
<property
name=
"LOG_DIR"
value=
"${LOG_PATH}/${
logName
}/%d{yyyyMMdd}"
/>
<property
name=
"LOG_DIR"
value=
"${LOG_PATH}/${
LOG_NAME
}/%d{yyyyMMdd}"
/>
<property
name=
"CHARSET"
value=
"UTF-8"
/>
<jmxConfigurator/>
...
...
@@ -31,9 +30,9 @@
<onMismatch>
DENY
</onMismatch>
</filter>
<!-- 定义文件的名称 -->
<file>
${LOG_PATH}/${
logName
}/error.log
</file>
<file>
${LOG_PATH}/${
LOG_NAME
}/error.log
</file>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<FileNamePattern>
${LOG_DIR}/err_${
logName
}%i.log
</FileNamePattern>
<FileNamePattern>
${LOG_DIR}/err_${
LOG_NAME
}%i.log
</FileNamePattern>
<MaxHistory>
${MAX_HISTORY}
</MaxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
${MAX_FILE_SIZE}
</maxFileSize>
...
...
@@ -46,9 +45,9 @@
<appender
name=
"APP"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!-- 定义文件的名称 -->
<file>
${LOG_PATH}/${
logName
}/app.log
</file>
<file>
${LOG_PATH}/${
LOG_NAME
}/app.log
</file>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<FileNamePattern>
${LOG_DIR}/all_${
logName
}%i.log
</FileNamePattern>
<FileNamePattern>
${LOG_DIR}/all_${
LOG_NAME
}%i.log
</FileNamePattern>
<MaxHistory>
${MAX_HISTORY}
</MaxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
${MAX_FILE_SIZE}
</maxFileSize>
...
...
@@ -80,17 +79,17 @@
</appender>
<logger
name=
"app"
level=
"${
logLevel
}"
>
<logger
name=
"app"
level=
"${
LOG_LEVEL
}"
>
<appender-ref
ref=
"ASYN_APP"
/>
</logger>
<logger
name=
"error"
level=
"${
logLevel
}"
>
<logger
name=
"error"
level=
"${
LOG_LEVEL
}"
>
<appender-ref
ref=
"ASYN_ERROR"
/>
</logger>
<!-- 日志排除 -->
<logger
name=
"org.logicalcobwebs.proxool"
level=
"error"
/>
<!--统一日志输出级别,其他appender中如果有高于此处等级设置的也会被输出 -->
<root
level=
"${
logLevel
}"
>
<root
level=
"${
LOG_LEVEL
}"
>
<springProfile
name=
"test,dev,local"
>
<appender-ref
ref=
"ASYN_STDOUT"
/>
</springProfile>
...
...
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