From f1913972b4bdab0c74c5cff9fb6c81eb9aa9ee68 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:05:13 -0500 Subject: [PATCH 1/4] fix log pipeline to kusto --- .../durabletask/DurableTaskGrpcWorker.java | 3 +- .../durabletask/OrchestrationRunner.java | 3 +- .../durabletask/log/FunctionKustoHandler.java | 37 +++++++++++++++++++ .../durabletask/log/LoggerManager.java | 35 ++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 client/src/main/java/com/microsoft/durabletask/log/FunctionKustoHandler.java create mode 100644 client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java diff --git a/client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java b/client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java index 92e2bda..576193c 100644 --- a/client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java +++ b/client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java @@ -9,6 +9,7 @@ import com.microsoft.durabletask.implementation.protobuf.OrchestratorService.WorkItem.RequestCase; import com.microsoft.durabletask.implementation.protobuf.TaskHubSidecarServiceGrpc.*; +import com.microsoft.durabletask.log.LoggerManager; import io.grpc.*; import java.time.Duration; @@ -22,7 +23,7 @@ */ public final class DurableTaskGrpcWorker implements AutoCloseable { private static final int DEFAULT_PORT = 4001; - private static final Logger logger = Logger.getLogger(DurableTaskGrpcWorker.class.getPackage().getName()); + private static final Logger logger = LoggerManager.getLogger(); private static final Duration DEFAULT_MAXIMUM_TIMER_INTERVAL = Duration.ofDays(3); private final HashMap orchestrationFactories = new HashMap<>(); diff --git a/client/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java b/client/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java index 1390490..19bc70a 100644 --- a/client/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java +++ b/client/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java @@ -5,6 +5,7 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.StringValue; import com.microsoft.durabletask.implementation.protobuf.OrchestratorService; +import com.microsoft.durabletask.log.LoggerManager; import java.time.Duration; import java.util.Base64; @@ -18,7 +19,7 @@ * caller must provide orchestration state as serialized protobuf bytes. */ public final class OrchestrationRunner { - private static final Logger logger = Logger.getLogger(OrchestrationRunner.class.getPackage().getName()); + private static final Logger logger = LoggerManager.getLogger(); private static final Duration DEFAULT_MAXIMUM_TIMER_INTERVAL = Duration.ofDays(3); private OrchestrationRunner() { diff --git a/client/src/main/java/com/microsoft/durabletask/log/FunctionKustoHandler.java b/client/src/main/java/com/microsoft/durabletask/log/FunctionKustoHandler.java new file mode 100644 index 0000000..0acf9e2 --- /dev/null +++ b/client/src/main/java/com/microsoft/durabletask/log/FunctionKustoHandler.java @@ -0,0 +1,37 @@ +package com.microsoft.durabletask.log; + +import java.io.PrintStream; +import java.util.Arrays; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +class FunctionKustoHandler extends Handler { + private static final String FUNCTIONSKUSTOPREFIX = "LanguageWorkerConsoleLog"; + private static final String DURABLEPREFIX = "DURABLE_JAVA_SDK"; + @Override + public void publish(LogRecord record) { + if (record != null && record.getLevel() != null) { + PrintStream output = record.getLevel().intValue() <= Level.INFO.intValue() ? System.out : System.err; + output.printf("%s%s [%s] {%s.%s}: %s%n", + FUNCTIONSKUSTOPREFIX, + DURABLEPREFIX, + record.getLevel(), + record.getSourceClassName(), + record.getSourceMethodName(), + record.getMessage()); + if (record.getThrown() != null) { + output.printf("%s%s%s%n", FUNCTIONSKUSTOPREFIX, DURABLEPREFIX, Arrays.toString(record.getThrown().getStackTrace())); + } + } + } + + @Override + public void flush() { + System.out.flush(); + System.err.flush(); + } + + @Override + public void close() throws SecurityException { } +} diff --git a/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java b/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java new file mode 100644 index 0000000..9b0b086 --- /dev/null +++ b/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java @@ -0,0 +1,35 @@ +package com.microsoft.durabletask.log; + +import java.util.Arrays; +import java.util.logging.*; + +public class LoggerManager { + private static final Logger logger = initLogger(); + + private static Logger initLogger() { + Logger logger = Logger.getAnonymousLogger(); + logger.setUseParentHandlers(false); + logger.setLevel(Level.ALL); + logger.addHandler(new FunctionKustoHandler()); + return logger; + } + + public static void setHandler(Handler handler) { + clearHandler(); + addHandler(handler); + } + + public static void addHandler(Handler handler) { + logger.addHandler(handler); + } + + private static void clearHandler() { + for (Handler handler : logger.getHandlers()) { + logger.removeHandler(handler); + } + } + + public static Logger getLogger() { + return logger; + } +} From a7000f697e6e7b8e2eec9e5d40f11d82f4b0041c Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:07:05 -0500 Subject: [PATCH 2/4] remove unused import --- .../main/java/com/microsoft/durabletask/log/LoggerManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java b/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java index 9b0b086..1a6be74 100644 --- a/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java +++ b/client/src/main/java/com/microsoft/durabletask/log/LoggerManager.java @@ -1,6 +1,5 @@ package com.microsoft.durabletask.log; -import java.util.Arrays; import java.util.logging.*; public class LoggerManager { From 9f500109d8efb046405513bf8a8db13485507225 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:12:52 -0500 Subject: [PATCH 3/4] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 380d783..94ad5fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## placeholder +* Update sdk loggin logics so all level logs are recored into kusto. ([#167](https://github.com/microsoft/durabletask-java/pull/167)) + ## v1.4.0 ### Updates From ec03495a14672402edf23807cdd221608fe2381a Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:27:29 -0500 Subject: [PATCH 4/4] correct pr link in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94ad5fa..14b4556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## placeholder -* Update sdk loggin logics so all level logs are recored into kusto. ([#167](https://github.com/microsoft/durabletask-java/pull/167)) +* Update sdk loggin logics so all level logs are recored into kusto. ([#170](https://github.com/microsoft/durabletask-java/pull/170)) ## v1.4.0