Skip to content

docs: Initial javadocs for PowerLogger class. #43

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

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/content/core/logger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew

## Appending additional keys

You can append your own keys to your existing Logger via `customKey`.
You can append your own keys to your existing Logger via `appendKey`.

```java:title=App.java
package helloworld;
Expand All @@ -135,7 +135,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
@PowerToolsLogging(logEvent = true)
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
...
PowerLogger.customKey("test", "willBeLogged");
PowerLogger.appendKey("test", "willBeLogged");
...
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");

PowerLogger.customKey("test", "willBeLogged");
PowerLogger.appendKey("test", "willBeLogged");

APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
.withHeaders(headers);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/software/amazon/lambda/logging/PowerLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import org.apache.logging.log4j.ThreadContext;

/**
* A class of helper functions to add additional functionality to PowerToolsLogging.
*
* {@see PowerToolsLogging}
*/
public class PowerLogger {

public static void customKey(String key, String value) {
/**
* Appends an additional key and value to each log entry made. Duplicate values
* for the same key will be replaced with the latest.
*
* @param key The name of the key to be logged
* @param value The value to be logged
*/
public static void appendKey(String key, String value) {
ThreadContext.put(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* <p>By default {@code PowerToolsLogging} will not log the event which has trigger the invoke of the Lambda function.
* This can be enabled using {@code @PowerToolsLogging(logEvent = true)}.</p>
*
* <p>To append additional keys to each log entry you can use {@link software.amazon.lambda.logging.PowerLogger#customKey(String, String)}</p>
* <p>To append additional keys to each log entry you can use {@link software.amazon.lambda.logging.PowerLogger#appendKey(String, String)}</p>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class LambdaJsonLayoutTest {

private RequestHandler<Object, Object> handler = new PowerLogToolEnabled();
private final RequestHandler<Object, Object> handler = new PowerLogToolEnabled();

@Mock
private Context context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void setUp() {

@Test
void shouldSetCustomKeyOnThreadContext() {
PowerLogger.customKey("test", "value");
PowerLogger.appendKey("test", "value");

assertThat(ThreadContext.getImmutableContext())
.hasSize(1)
Expand Down