Skip to content

Commit 484e501

Browse files
authored
docs: Initial javadocs for PowerLogger class. (#43)
* docs: Initial javadocs for our logging annotation. * docs: Initial javadocs for PowerLogger class.
1 parent 471909c commit 484e501

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

docs/content/core/logger.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
114114

115115
## Appending additional keys
116116

117-
You can append your own keys to your existing Logger via `customKey`.
117+
You can append your own keys to your existing Logger via `appendKey`.
118118

119119
```java:title=App.java
120120
package helloworld;
@@ -135,7 +135,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
135135
@PowerToolsLogging(logEvent = true)
136136
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
137137
...
138-
PowerLogger.customKey("test", "willBeLogged");
138+
PowerLogger.appendKey("test", "willBeLogged");
139139
...
140140
}
141141
}

example/HelloWorldFunction/src/main/java/helloworld/App.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
3939
headers.put("Content-Type", "application/json");
4040
headers.put("X-Custom-Header", "application/json");
4141

42-
PowerLogger.customKey("test", "willBeLogged");
42+
PowerLogger.appendKey("test", "willBeLogged");
4343

4444
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
4545
.withHeaders(headers);

src/main/java/software/amazon/lambda/logging/PowerLogger.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
import org.apache.logging.log4j.ThreadContext;
44

5+
/**
6+
* A class of helper functions to add additional functionality to PowerToolsLogging.
7+
*
8+
* {@see PowerToolsLogging}
9+
*/
510
public class PowerLogger {
611

7-
public static void customKey(String key, String value) {
12+
/**
13+
* Appends an additional key and value to each log entry made. Duplicate values
14+
* for the same key will be replaced with the latest.
15+
*
16+
* @param key The name of the key to be logged
17+
* @param value The value to be logged
18+
*/
19+
public static void appendKey(String key, String value) {
820
ThreadContext.put(key, value);
921
}
1022
}

src/main/java/software/amazon/lambda/logging/PowerToolsLogging.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* <p>By default {@code PowerToolsLogging} will not log the event which has trigger the invoke of the Lambda function.
4141
* This can be enabled using {@code @PowerToolsLogging(logEvent = true)}.</p>
4242
*
43-
* <p>To append additional keys to each log entry you can use {@link software.amazon.lambda.logging.PowerLogger#customKey(String, String)}</p>
43+
* <p>To append additional keys to each log entry you can use {@link software.amazon.lambda.logging.PowerLogger#appendKey(String, String)}</p>
4444
*/
4545
@Retention(RetentionPolicy.RUNTIME)
4646
@Target(ElementType.METHOD)

src/test/java/org/apache/logging/log4j/core/layout/LambdaJsonLayoutTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class LambdaJsonLayoutTest {
2727

28-
private RequestHandler<Object, Object> handler = new PowerLogToolEnabled();
28+
private final RequestHandler<Object, Object> handler = new PowerLogToolEnabled();
2929

3030
@Mock
3131
private Context context;

src/test/java/software/amazon/lambda/logging/PowerLoggerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void setUp() {
1616

1717
@Test
1818
void shouldSetCustomKeyOnThreadContext() {
19-
PowerLogger.customKey("test", "value");
19+
PowerLogger.appendKey("test", "value");
2020

2121
assertThat(ThreadContext.getImmutableContext())
2222
.hasSize(1)

0 commit comments

Comments
 (0)