-
Notifications
You must be signed in to change notification settings - Fork 241
Add Log4J 2 Logging Support #7
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
Add Log4j 2 support
- Loading branch information
There are no files selected for viewing
This file contains hidden or 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,136 @@ | ||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-lambda-java-log4j2</artifactId> | ||
| <version>1.0.0</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>AWS Lambda Java Log4j 2 Library</name> | ||
| <description> | ||
| Support for using log4j 2 with AWS Lambda. | ||
| </description> | ||
| <url>https://aws.amazon.com/lambda/</url> | ||
| <licenses> | ||
| <license> | ||
| <name>Apache License, Version 2.0</name> | ||
| <url>https://aws.amazon.com/apache2.0</url> | ||
| <distribution>repo</distribution> | ||
| </license> | ||
| </licenses> | ||
| <scm> | ||
| <url>https://github.com/aws/aws-lambda-java-libs.git</url> | ||
| </scm> | ||
| <developers> | ||
| <developer> | ||
| <name>AWS Lambda team</name> | ||
| <organization>Amazon Web Services</organization> | ||
| <organizationUrl>https://aws.amazon.com/</organizationUrl> | ||
| </developer> | ||
| </developers> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-lambda-java-core</artifactId> | ||
| <version>1.1.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| <version>2.5</version> | ||
| </dependency> | ||
| </dependencies> | ||
| <distributionManagement> | ||
| <repository> | ||
| <id>sonatype-nexus-staging</id> | ||
| <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> | ||
| </repository> | ||
| </distributionManagement> | ||
|
|
||
| <profiles> | ||
| <profile> | ||
| <id>dev</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-javadoc-plugin</artifactId> | ||
| <version>2.9.1</version> | ||
| <configuration> | ||
| <additionalparam>-Xdoclint:none</additionalparam> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-javadocs</id> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| <profile> | ||
| <id>release</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-source-plugin</artifactId> | ||
| <version>2.2.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-sources</id> | ||
| <goals> | ||
| <goal>jar-no-fork</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-javadoc-plugin</artifactId> | ||
| <version>2.9.1</version> | ||
| <configuration> | ||
| <additionalparam>-Xdoclint:none</additionalparam> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-javadocs</id> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-gpg-plugin</artifactId> | ||
| <version>1.5</version> | ||
| <executions> | ||
| <execution> | ||
| <id>sign-artifacts</id> | ||
| <phase>verify</phase> | ||
| <goals> | ||
| <goal>sign</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.sonatype.plugins</groupId> | ||
| <artifactId>nexus-staging-maven-plugin</artifactId> | ||
| <version>1.6.3</version> | ||
| <extensions>true</extensions> | ||
| <configuration> | ||
| <serverId>sonatype-nexus-staging</serverId> | ||
| <nexusUrl>https://oss.sonatype.org/</nexusUrl> | ||
| <autoReleaseAfterClose>false</autoReleaseAfterClose> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> |
52 changes: 52 additions & 0 deletions
52
...java-log4j2/src/main/java/com/amazonaws/services/lambda/runtime/log4j/LambdaAppender.java
This file contains hidden or 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,52 @@ | ||
| package com.amazonaws.services.lambda.runtime.log4j; | ||
|
|
||
|
|
||
| import com.amazonaws.services.lambda.runtime.LambdaRuntime; | ||
| import com.amazonaws.services.lambda.runtime.LambdaLogger; | ||
| import org.apache.logging.log4j.core.Filter; | ||
| import org.apache.logging.log4j.core.Layout; | ||
| import org.apache.logging.log4j.core.LogEvent; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| 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.PatternLayout; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * LambdaAppender is the custom log4j appender | ||
| * to be used in the log4j.properties file. | ||
| * You should not be required to use this class directly. | ||
| */ | ||
| @Plugin(name = "Lambda", category = "Core", elementType = "appender", printObject = true) | ||
| public class LambdaAppender extends AbstractAppender { | ||
|
|
||
| LambdaLogger logger = LambdaRuntime.getLogger(); | ||
|
|
||
| private LambdaAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) { | ||
| super(name, filter, layout, ignoreExceptions); | ||
| } | ||
|
|
||
| public void append(LogEvent event) { | ||
| logger.log(new String(getLayout().toByteArray(event))); | ||
| } | ||
|
|
||
| @PluginFactory | ||
| public static LambdaAppender createAppender(@PluginAttribute("name") String name, | ||
| @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, | ||
| @PluginElement("Layout") Layout<? extends Serializable> layout, | ||
| @PluginElement("Filters") Filter filter) { | ||
| if (name == null) { | ||
| LOGGER.error("No name provided for LambdaAppender"); | ||
| return null; | ||
| } | ||
|
|
||
| if (layout == null) { | ||
| layout = PatternLayout.createDefaultLayout(); | ||
| } | ||
| return new LambdaAppender(name, filter, layout, ignoreExceptions); | ||
| } | ||
|
|
||
| } | ||
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.
Recommend ensuring some sort of reasonable encoding here: UTF-8?