Skip to content

Commit 60f099a

Browse files
committed
1.0.0 release of AWS Lambda logj support.
1 parent d3e3142 commit 60f099a

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed

aws-lambda-java-logj4/pom.xml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>com.amazonaws</groupId>
5+
<artifactId>aws-lambda-java-log4j</artifactId>
6+
<version>1.0.0</version>
7+
<packaging>jar</packaging>
8+
9+
<name>AWS Lambda Java Log4j 1.2 Library</name>
10+
<description>
11+
Support for using log4j 1.2 with AWS Lambda.
12+
</description>
13+
<url>https://aws.amazon.com/lambda/</url>
14+
<licenses>
15+
<license>
16+
<name>Apache License, Version 2.0</name>
17+
<url>https://aws.amazon.com/apache2.0</url>
18+
<distribution>repo</distribution>
19+
</license>
20+
</licenses>
21+
<scm>
22+
<url>https://github.com/aws/aws-lambda-java-libs.git</url>
23+
</scm>
24+
<developers>
25+
<developer>
26+
<name>AWS Lambda team</name>
27+
<organization>Amazon Web Services</organization>
28+
<organizationUrl>https://aws.amazon.com/</organizationUrl>
29+
</developer>
30+
</developers>
31+
<dependencies>
32+
<dependency>
33+
<groupId>com.amazonaws</groupId>
34+
<artifactId>aws-lambda-java-core</artifactId>
35+
<version>1.1.0</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>log4j</groupId>
39+
<artifactId>log4j</artifactId>
40+
<version>1.2.17</version>
41+
</dependency>
42+
</dependencies>
43+
<distributionManagement>
44+
<repository>
45+
<id>sonatype-nexus-staging</id>
46+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
47+
</repository>
48+
</distributionManagement>
49+
50+
<profiles>
51+
<profile>
52+
<id>dev</id>
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-javadoc-plugin</artifactId>
58+
<version>2.9.1</version>
59+
<configuration>
60+
<additionalparam>-Xdoclint:none</additionalparam>
61+
</configuration>
62+
<executions>
63+
<execution>
64+
<id>attach-javadocs</id>
65+
<goals>
66+
<goal>jar</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
</profile>
74+
<profile>
75+
<id>release</id>
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-source-plugin</artifactId>
81+
<version>2.2.1</version>
82+
<executions>
83+
<execution>
84+
<id>attach-sources</id>
85+
<goals>
86+
<goal>jar-no-fork</goal>
87+
</goals>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-javadoc-plugin</artifactId>
94+
<version>2.9.1</version>
95+
<configuration>
96+
<additionalparam>-Xdoclint:none</additionalparam>
97+
</configuration>
98+
<executions>
99+
<execution>
100+
<id>attach-javadocs</id>
101+
<goals>
102+
<goal>jar</goal>
103+
</goals>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
<plugin>
108+
<groupId>org.apache.maven.plugins</groupId>
109+
<artifactId>maven-gpg-plugin</artifactId>
110+
<version>1.5</version>
111+
<executions>
112+
<execution>
113+
<id>sign-artifacts</id>
114+
<phase>verify</phase>
115+
<goals>
116+
<goal>sign</goal>
117+
</goals>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
<plugin>
122+
<groupId>org.sonatype.plugins</groupId>
123+
<artifactId>nexus-staging-maven-plugin</artifactId>
124+
<version>1.6.3</version>
125+
<extensions>true</extensions>
126+
<configuration>
127+
<serverId>sonatype-nexus-staging</serverId>
128+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
129+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
130+
</configuration>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
</profile>
135+
</profiles>
136+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.amazonaws.services.lambda.runtime.log4j;
2+
3+
import org.apache.log4j.AppenderSkeleton;
4+
import org.apache.log4j.spi.LoggingEvent;
5+
import org.apache.log4j.Layout;
6+
7+
import com.amazonaws.services.lambda.runtime.LambdaRuntime;
8+
import com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal;
9+
import com.amazonaws.services.lambda.runtime.LambdaLogger;
10+
11+
/**
12+
* LambdaAppender is the custom log4j appender
13+
* to be used in the log4j.properties file.
14+
* You should not be required to use this class directly.
15+
*/
16+
public class LambdaAppender extends AppenderSkeleton {
17+
18+
LambdaLogger logger = LambdaRuntime.getLogger();
19+
20+
public LambdaAppender() {
21+
super();
22+
LambdaRuntimeInternal.setUseLog4jAppender(true);
23+
}
24+
25+
@Override
26+
protected void append(LoggingEvent event) {
27+
if(this.layout == null) {
28+
logger.log(event.getLevel() + " " + event.getMessage());
29+
return;
30+
}
31+
logger.log(this.layout.format(event));
32+
//prints the Throwable from the log
33+
if(layout.ignoresThrowable()) {
34+
StringBuilder traceString = new StringBuilder();
35+
String[] s = event.getThrowableStrRep();
36+
if (s != null) {
37+
int len = s.length;
38+
for(int i = 0; i < len; i++) {
39+
traceString.append(s[i]);
40+
traceString.append(Layout.LINE_SEP);
41+
}
42+
}
43+
logger.log(traceString.toString());
44+
}
45+
}
46+
47+
public void close() {
48+
}
49+
50+
public boolean requiresLayout() {
51+
return true;
52+
}
53+
}

0 commit comments

Comments
 (0)