Skip to content

Commit 3722925

Browse files
committed
feat(gax): add utilities for logging actionable errors
1 parent a1b7565 commit 3722925

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

gax-java/gax/src/main/java/com/google/api/gax/logging/LoggingUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ public static <RespT> void logRequest(
126126
}
127127
}
128128

129+
/**
130+
* Logs an actionable error message with structured context.
131+
*
132+
* @param logContext A map containing the structured logging context (e.g., RPC service, method,
133+
* error details).
134+
* @param loggerProvider The provider used to obtain the logger.
135+
* @param message The human-readable error message.
136+
*/
137+
public static void logActionableError(
138+
Map<String, Object> logContext, LoggerProvider loggerProvider, String message) {
139+
if (loggingEnabled) {
140+
org.slf4j.Logger logger = loggerProvider.getLogger();
141+
if (logger.isInfoEnabled()) {
142+
Slf4jUtils.log(logger, org.slf4j.event.Level.INFO, logContext, message);
143+
}
144+
}
145+
}
146+
129147
public static void executeWithTryCatch(ThrowingRunnable action) {
130148
try {
131149
action.run();

0 commit comments

Comments
 (0)