Skip to content

Commit

Permalink
Merge pull request #64 from jklap/feature/aws-v2
Browse files Browse the repository at this point in the history
Support for AWS SDK v2
  • Loading branch information
sndyuk authored Apr 24, 2021
2 parents 00ebe93 + 30c3c25 commit 5f615ea
Show file tree
Hide file tree
Showing 8 changed files with 830 additions and 18 deletions.
32 changes: 24 additions & 8 deletions pom-JAVA9MODULE_SLF4J17.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

<properties>
<fluentd.logger.version>0.3.4</fluentd.logger.version>
<fluency.version>2.4.1</fluency.version>
<fluency.version>2.5.1</fluency.version>
<logback.version>1.2.3</logback.version>
<slf4j.version>1.7.26</slf4j.version>
<jackson.version>2.9.8</jackson.version>
<aws.version>1.11.504</aws.version>
<jackson.version>2.12.3</jackson.version>
<aws.version>1.11.1000</aws.version>
<aws-v2.version>2.16.43</aws-v2.version>
<jdk.version>9</jdk.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>
Expand All @@ -33,7 +34,7 @@
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.11</version>
<version>4.0</version>
<configuration>
<aggregate>true</aggregate>
<strictCheck>true</strictCheck>
Expand All @@ -47,7 +48,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<version>3.2.0</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
Expand Down Expand Up @@ -86,7 +87,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -99,6 +100,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -109,13 +111,13 @@
</executions>
<configuration>
<source>8</source>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalParam>-Xdoclint:none</additionalParam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.2</version>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -192,6 +194,20 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>cloudwatchlogs</artifactId>
<version>${aws-v2.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>kinesis</artifactId>
<version>${aws-v2.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
36 changes: 26 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

<properties>
<fluentd.logger.version>0.3.4</fluentd.logger.version>
<fluency.version>2.4.1</fluency.version>
<fluency.version>2.5.1</fluency.version>
<logback.version>1.2.3</logback.version>
<jackson.version>2.9.8</jackson.version>
<aws.version>1.11.642</aws.version>
<jdk.version>7</jdk.version>
<jackson.version>2.12.3</jackson.version>
<aws.version>1.11.1000</aws.version>
<aws-v2.version>2.16.43</aws-v2.version>
<jdk.version>8</jdk.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>

Expand All @@ -32,7 +33,7 @@
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.11</version>
<version>4.0</version>
<configuration>
<aggregate>true</aggregate>
<strictCheck>true</strictCheck>
Expand All @@ -46,14 +47,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<version>3.2.0</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${jdk.version}</source>
Expand All @@ -63,7 +65,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -76,7 +78,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -87,13 +89,13 @@
</executions>
<configuration>
<source>${jdk.version}</source>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalParam>-Xdoclint:none</additionalParam>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.2</version>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -155,6 +157,20 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>cloudwatchlogs</artifactId>
<version>${aws-v2.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>kinesis</artifactId>
<version>${aws-v2.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/ch/qos/logback/more/appenders/AwsAppenderV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2018 sndyuk <[email protected]>
*
* 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 ch.qos.logback.more.appenders;

import ch.qos.logback.core.AppenderBase;
import software.amazon.awssdk.auth.credentials.*;

import java.util.Properties;


public abstract class AwsAppenderV2<E> extends AppenderBase<E> {

protected AwsConfig config;
protected AwsCredentialsProvider credentialsProvider;
protected AwsCredentials credentials;

@Override
public void start() {
try {
if (config.getCredentialFilePath() != null
&& config.getCredentialFilePath().length() > 0) {
Properties props = new Properties();
props.load(getClass().getClassLoader().getResourceAsStream(config.getCredentialFilePath()));
this.credentialsProvider = StaticCredentialsProvider.create(
AwsBasicCredentials.create(props.getProperty("accessKey"), props.getProperty("secretKey")));
} else
if (config.getProfile() != null && config.getProfile().length() > 0) {
this.credentialsProvider = DefaultCredentialsProvider.builder().profileName(config.getProfile()).build();
} else {
this.credentialsProvider = DefaultCredentialsProvider.create();
}
super.start();
} catch (Exception e) {
addWarn("Could not initialize " + AwsAppenderV2.class.getCanonicalName()
+ " ( will try to initialize again later ): " + e);
}
}

public static class AwsConfig {
private String credentialFilePath;
private String region;
private String profile;

public void setCredentialFilePath(String credentialFilePath) {
this.credentialFilePath = credentialFilePath;
}

public String getCredentialFilePath() {
return credentialFilePath;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}
}
}
Loading

0 comments on commit 5f615ea

Please sign in to comment.