-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from shiyindaxiaojie/feature
Feature
- Loading branch information
Showing
13 changed files
with
233 additions
and
31 deletions.
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
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
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
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
10 changes: 5 additions & 5 deletions
10
...starters/eden-idempotent-spring-boot-starter/src/main/resources/META-INF/spring.factories
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Auto Configure | ||
#org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
# org.ylzl.eden.idempotent.spring.boot.autoconfigure.TimeToLiveIdempotentAutoConfiguration,\ | ||
# org.ylzl.eden.idempotent.spring.boot.autoconfigure.TokenIdempotentAutoConfiguration,\ | ||
# org.ylzl.eden.idempotent.spring.boot.autoconfigure.RedisTimeToLiveIdempotentAutoConfiguration,\ | ||
# org.ylzl.eden.idempotent.spring.boot.autoconfigure.RedisTokenIdempotentAutoConfiguration | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
org.ylzl.eden.idempotent.spring.boot.autoconfigure.TimeToLiveIdempotentAutoConfiguration,\ | ||
org.ylzl.eden.idempotent.spring.boot.autoconfigure.TokenIdempotentAutoConfiguration,\ | ||
org.ylzl.eden.idempotent.spring.boot.autoconfigure.RedisTimeToLiveIdempotentAutoConfiguration,\ | ||
org.ylzl.eden.idempotent.spring.boot.autoconfigure.RedisTokenIdempotentAutoConfiguration |
57 changes: 57 additions & 0 deletions
57
eden-components/eden-spring-boot-starters/eden-loki-spring-boot-starter/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,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2012-2019 the original author or authors. | ||
~ | ||
~ 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.shiyindaxiaojie</groupId> | ||
<artifactId>eden-spring-boot-starters</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>eden-loki-spring-boot-starter</artifactId> | ||
<packaging>jar</packaging> | ||
<name>eden-loki-spring-boot-starter</name> | ||
<description>Spring Boot Starter For Loki</description> | ||
|
||
<dependencies> | ||
<!-- 开发框架 --> | ||
<dependency> | ||
<groupId>io.github.shiyindaxiaojie</groupId> | ||
<artifactId>eden-spring-boot</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.shiyindaxiaojie</groupId> | ||
<artifactId>eden-spring-integration</artifactId> | ||
</dependency> | ||
|
||
<!-- 开发组件 --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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
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
104 changes: 104 additions & 0 deletions
104
...ain/java/org/ylzl/eden/spring/integration/loki/integration/log4j2/Log4j2LokiAppender.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,104 @@ | ||
package org.ylzl.eden.spring.integration.loki.integration.log4j2; | ||
|
||
import com.dianping.cat.Cat; | ||
import com.dianping.cat.message.Message; | ||
import lombok.SneakyThrows; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.*; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
import org.apache.logging.log4j.core.appender.AppenderLoggingException; | ||
import org.apache.logging.log4j.core.config.Property; | ||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.config.plugins.PluginAttribute; | ||
import org.apache.logging.log4j.core.config.plugins.PluginElement; | ||
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.core.layout.JsonLayout; | ||
import org.apache.logging.log4j.core.layout.PatternLayout; | ||
import org.apache.logging.log4j.core.util.Booleans; | ||
import org.ylzl.eden.commons.env.Charsets; | ||
import org.ylzl.eden.spring.integration.cat.CatConstants; | ||
|
||
import java.io.Serializable; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* Log4j2 附加器 | ||
* | ||
* @author <a href="mailto:[email protected]">gyl</a> | ||
* @since 2.4.13 | ||
*/ | ||
@Plugin(name = Log4j2LokiAppender.NAME, category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) | ||
public class Log4j2LokiAppender extends AbstractAppender { | ||
|
||
public static final String NAME = "Loki"; | ||
|
||
private static final int DEFAULT_MAX_LENGTH = 500; | ||
|
||
private final Level level; | ||
|
||
private final Integer maxLength; | ||
|
||
public Log4j2LokiAppender(String name, Filter filter, Layout<? extends Serializable> layout, | ||
boolean ignoreExceptions, Property[] properties, Level level, Integer maxLength) { | ||
super(name, filter, layout, ignoreExceptions, properties); | ||
this.level = level; | ||
this.maxLength = maxLength != null && maxLength > 0 ? maxLength : DEFAULT_MAX_LENGTH; | ||
} | ||
|
||
@Override | ||
public void append(LogEvent event) { | ||
try { | ||
if (event.getLevel().isMoreSpecificThan(level)) { | ||
// TODO | ||
} | ||
} catch (Exception ex) { | ||
if (!ignoreExceptions()) { | ||
throw new AppenderLoggingException(ex); | ||
} | ||
} | ||
} | ||
|
||
@SneakyThrows(UnsupportedEncodingException.class) | ||
private void tryAppend(final LogEvent event) { | ||
Layout<? extends Serializable> layout = getLayout(); | ||
byte[] data; | ||
if (layout instanceof JsonLayout) { | ||
final byte[] header = layout.getHeader(); | ||
final byte[] body = layout.toByteArray(event); | ||
data = new byte[header.length + body.length]; | ||
System.arraycopy(header, 0, data, 0, header.length); | ||
System.arraycopy(body, 0, data, header.length, body.length); | ||
} else { | ||
data = layout.toByteArray(event); | ||
} | ||
String message = data.length > maxLength ? | ||
new String(data, 0, maxLength, Charsets.UTF_8_NAME) : | ||
new String(data, Charsets.UTF_8_NAME); | ||
Cat.logEvent(CatConstants.TYPE_LOG_LOG4J2, event.getLevel().name(), Message.SUCCESS, message); | ||
} | ||
|
||
@PluginFactory | ||
public static Log4j2LokiAppender build( | ||
@PluginAttribute("name") String name, | ||
@PluginElement("Filter") Filter filter, | ||
@PluginElement("Layout") Layout<? extends Serializable> layout, | ||
@PluginAttribute("ignoreExceptions") String ignore, | ||
@PluginAttribute("level") Level level, | ||
@PluginAttribute("maxLength") Integer maxLength) { | ||
|
||
if (name == null) { | ||
return null; | ||
} | ||
if (layout == null) { | ||
layout = PatternLayout.createDefaultLayout(); | ||
} | ||
if (level == null) { | ||
level = Level.ERROR; | ||
} | ||
if (maxLength == null) { | ||
maxLength = DEFAULT_MAX_LENGTH; | ||
} | ||
boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); | ||
return new Log4j2LokiAppender(name, filter, layout, ignoreExceptions, null, level, maxLength); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../src/main/java/org/ylzl/eden/spring/integration/loki/integration/log4j2/package-info.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 @@ | ||
package org.ylzl.eden.spring.integration.loki.integration.log4j2; |
1 change: 1 addition & 0 deletions
1
...src/main/java/org/ylzl/eden/spring/integration/loki/integration/logback/package-info.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 @@ | ||
package org.ylzl.eden.spring.integration.loki.integration.logback; |
1 change: 1 addition & 0 deletions
1
...-spring-integration/src/main/java/org/ylzl/eden/spring/integration/loki/package-info.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 @@ | ||
package org.ylzl.eden.spring.integration.loki; |
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