-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SLF4J extension #1344
Merged
Merged
Add SLF4J extension #1344
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff4e7d5
Merge pull request #1 from alibaba/master
wavesZh 1a3510f
Merge branch 'master' of github.com:wavesZh/Sentinel
wavesZh 380fd93
Merge remote-tracking branch 'upstream/master'
wavesZh f451f4f
Merge remote-tracking branch 'upstream/master'
wavesZh 41201d0
Merge remote-tracking branch 'upstream/master'
wavesZh 77fb922
Merge remote-tracking branch 'upstream/master'
wavesZh 6e176f9
Merge branch 'master' of github.com:wavesZh/Sentinel
wavesZh 57fc6d0
Merge remote-tracking branch 'upstream/master'
wavesZh 761ce34
Merge remote-tracking branch 'upstream/master'
wavesZh 331359c
add logging extension for SLF4J
wavesZh 0d9c07c
Merge remote-tracking branch 'upstream/master' into slf4j-extension
wavesZh 6936d7c
add license header
wavesZh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
sentinel-extension/sentinel-logging-extension-slf4j/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Sentinel Logging Extension SLF4J | ||
|
||
To use Sentinel Logging Extension SLF4J with Log4j2, you should add the following dependency firstly: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-logging-extension-slf4j</artifactId> | ||
<version>x.y.z</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
jasonjoo2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
If you want to use Slf4j with Log4j2, you can add dependencies of Log4j2 and the binding about Log4j2 and SLF4J. | ||
Then you should provide logging configuration as specification of the logging framework. | ||
And you can add Sentinel's Loggers that it name is `sentinelRecordLogger` or `sentinelCommandCenterLogger` for your needs. For example: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Configuration> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%-5level %logger - %msg%n"/> | ||
</Console> | ||
<File name="FILE" fileName="sentinel-record.log" append="false"> | ||
<PatternLayout pattern="%-5level %logger - %msg%n"/> | ||
</File> | ||
<File name="FILE2" fileName="sentinel-command-center.log" append="false"> | ||
<PatternLayout pattern="%-5level %logger - %msg%n"/> | ||
</File> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="info"/> | ||
<logger name="sentinelRecordLogger" level="trace"> | ||
<appender-ref ref="Console" /> | ||
<appender-ref ref="FILE" /> | ||
</logger> | ||
<logger name="sentinelCommandCenterLogger" level="trace"> | ||
<appender-ref ref="Console" /> | ||
<appender-ref ref="FILE2" /> | ||
</logger> | ||
</Loggers> | ||
</Configuration> | ||
``` | ||
|
||
|
60 changes: 60 additions & 0 deletions
60
sentinel-extension/sentinel-logging-extension-slf4j/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>sentinel-parent</artifactId> | ||
<groupId>com.alibaba.csp</groupId> | ||
<version>1.7.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>sentinel-logging-extension-slf4j</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<java.source.version>1.7</java.source.version> | ||
<java.target.version>1.7</java.target.version> | ||
<slf4j.version>1.7.25</slf4j.version> | ||
<log4j2.version>2.12.1</log4j2.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-transport-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>${log4j2.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
jasonjoo2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<version>${log4j2.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.stefanbirkner</groupId> | ||
<artifactId>system-rules</artifactId> | ||
<version>1.16.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
81 changes: 81 additions & 0 deletions
81
...on-slf4j/src/main/java/com/alibaba/csp/sentinel/logging/slf4j/CommandCenterLogLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.logging.slf4j; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add the license header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
import com.alibaba.csp.sentinel.log.LogTarget; | ||
import com.alibaba.csp.sentinel.log.Logger; | ||
import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author wavesZh | ||
*/ | ||
@LogTarget(CommandCenterLog.LOGGER_NAME) | ||
public class CommandCenterLogLogger implements Logger { | ||
|
||
private final org.slf4j.Logger logger = LoggerFactory.getLogger(CommandCenterLog.LOGGER_NAME); | ||
|
||
@Override | ||
public void info(String format, Object... arguments) { | ||
logger.info(format, arguments); | ||
} | ||
|
||
@Override | ||
public void info(String msg, Throwable e) { | ||
logger.info(msg, e); | ||
} | ||
|
||
@Override | ||
public void warn(String format, Object... arguments) { | ||
logger.warn(format, arguments); | ||
} | ||
|
||
@Override | ||
public void warn(String msg, Throwable e) { | ||
logger.warn(msg, e); | ||
} | ||
|
||
@Override | ||
public void trace(String format, Object... arguments) { | ||
logger.trace(format, arguments); | ||
} | ||
|
||
@Override | ||
public void trace(String msg, Throwable e) { | ||
logger.trace(msg, e); | ||
} | ||
|
||
@Override | ||
public void debug(String format, Object... arguments) { | ||
logger.debug(format, arguments); | ||
} | ||
|
||
@Override | ||
public void debug(String msg, Throwable e) { | ||
logger.debug(msg, e); | ||
} | ||
|
||
@Override | ||
public void error(String format, Object... arguments) { | ||
logger.error(format, arguments); | ||
} | ||
|
||
@Override | ||
public void error(String msg, Throwable e) { | ||
logger.error(msg, e); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...extension-slf4j/src/main/java/com/alibaba/csp/sentinel/logging/slf4j/RecordLogLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.logging.slf4j; | ||
|
||
import com.alibaba.csp.sentinel.log.LogTarget; | ||
import com.alibaba.csp.sentinel.log.Logger; | ||
import com.alibaba.csp.sentinel.log.RecordLog; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author wavesZh | ||
*/ | ||
@LogTarget(RecordLog.LOGGER_NAME) | ||
public class RecordLogLogger implements Logger { | ||
|
||
private final org.slf4j.Logger logger = LoggerFactory.getLogger(RecordLog.LOGGER_NAME); | ||
|
||
@Override | ||
public void info(String format, Object... arguments) { | ||
logger.info(format, arguments); | ||
} | ||
|
||
@Override | ||
public void info(String msg, Throwable e) { | ||
logger.info(msg, e); | ||
} | ||
|
||
@Override | ||
public void warn(String format, Object... arguments) { | ||
logger.warn(format, arguments); | ||
} | ||
|
||
@Override | ||
public void warn(String msg, Throwable e) { | ||
logger.warn(msg, e); | ||
} | ||
|
||
@Override | ||
public void trace(String format, Object... arguments) { | ||
logger.trace(format, arguments); | ||
} | ||
|
||
@Override | ||
public void trace(String msg, Throwable e) { | ||
logger.trace(msg, e); | ||
} | ||
|
||
@Override | ||
public void debug(String format, Object... arguments) { | ||
logger.debug(format, arguments); | ||
} | ||
|
||
@Override | ||
public void debug(String msg, Throwable e) { | ||
logger.debug(msg, e); | ||
} | ||
|
||
@Override | ||
public void error(String format, Object... arguments) { | ||
logger.error(format, arguments); | ||
} | ||
|
||
@Override | ||
public void error(String msg, Throwable e) { | ||
logger.error(msg, e); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...-extension-slf4j/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.log.Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
com.alibaba.csp.sentinel.logging.slf4j.RecordLogLogger | ||
com.alibaba.csp.sentinel.logging.slf4j.CommandCenterLogLogger |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just call it
sentinel-logging-slf4j
for short.And is it necessary to create a new module in the same level as
sentinel-extension
calledsentinel-logging
? Thus some common logic can be put into a package likesentinel-logging-common
maybe. Just a proposal and @sczyh30 you can comment it here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things change a lot.
So for summary the only undetermined point is:
Coming to README.md my opinion is making it simple which is enough. But i am okay if you have different viewpoint.