Skip to content

Commit a4916a9

Browse files
authored
[alc] Interface changes in the core package (#434)
Co-authored-by: Daniel Torok <[email protected]>
1 parent 1d7822e commit a4916a9

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/LambdaLogger.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package com.amazonaws.services.lambda.runtime;
44

5+
import com.amazonaws.services.lambda.runtime.logging.LogLevel;
6+
57
/**
68
* A low level Lambda runtime logger
79
*
@@ -10,7 +12,7 @@ public interface LambdaLogger {
1012

1113
/**
1214
* Logs a string to AWS CloudWatch Logs
13-
*
15+
*
1416
* <p>
1517
* Logging will not be done:
1618
* <ul>
@@ -22,7 +24,7 @@ public interface LambdaLogger {
2224
* </li>
2325
* </ul>
2426
* </p>
25-
*
27+
*
2628
* @param message A string containing the event to log.
2729
*/
2830
void log(String message);
@@ -32,5 +34,27 @@ public interface LambdaLogger {
3234
* @param message byte array containing logs
3335
*/
3436
void log(byte[] message);
37+
38+
/**
39+
* LogLevel aware logging backend function.
40+
*
41+
* @param message in String format
42+
* @param logLevel
43+
*/
44+
default void log(String message, LogLevel logLevel) {
45+
log(message);
46+
}
47+
48+
/**
49+
* LogLevel aware logging backend function.
50+
*
51+
* @param message in byte[] format
52+
* @param logLevel
53+
*/
54+
default void log(byte[] message, LogLevel logLevel) {
55+
log(message);
56+
}
57+
58+
3559
}
3660

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
package com.amazonaws.services.lambda.runtime.logging;
4+
5+
6+
public enum LogFormat {
7+
JSON,
8+
TEXT;
9+
10+
public static LogFormat fromString(String logFormat) {
11+
try {
12+
return LogFormat.valueOf(logFormat.toUpperCase());
13+
} catch (Exception e) {
14+
throw new IllegalArgumentException("Invalid log format: '" + logFormat + "' expected one of [JSON, TEXT]");
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
package com.amazonaws.services.lambda.runtime.logging;
4+
5+
6+
public enum LogLevel {
7+
// UNDEFINED log level is used when the legacy LambdaLogger::log(String) function is called
8+
// where the loglevel is not defined. In this case we're not filtering the message in the runtime
9+
UNDEFINED,
10+
TRACE,
11+
DEBUG,
12+
INFO,
13+
WARN,
14+
ERROR,
15+
FATAL;
16+
17+
public static LogLevel fromString(String logLevel) {
18+
try {
19+
return LogLevel.valueOf(logLevel.toUpperCase());
20+
} catch (Exception e) {
21+
throw new IllegalArgumentException(
22+
"Invalid log level: '" + logLevel + "' expected one of [TRACE, DEBUG, INFO, WARN, ERROR, FATAL]");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)