aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2024-05-27 14:24:20 +0200
committerGitHub <noreply@github.com>2024-05-27 14:24:20 +0200
commit69d3e9d2a88f7766e5e06d8384cff1923bb2885f (patch)
treefb3ddd78b184325349c8f3b8cc6d4f7b41ec1381
parent0e27e5f9e7b7cfbf643ff1aca66ab3fd24a29143 (diff)
parentec7ced6dddc9e91b980bada08eabee3fdd3198cb (diff)
Merge pull request #31314 from vespa-engine/bjorncs/feed-client-logging
Allow log configuration file to be overridden
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java11
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java13
-rw-r--r--vespa-feed-client-cli/src/test/resources/help.txt6
3 files changed, 30 insertions, 0 deletions
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
index 35faa89388b..b365446db6d 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
@@ -61,6 +61,7 @@ class CliArguments {
private static final String DOOM_OPTION = "max-failure-seconds";
private static final String PROXY_OPTION = "proxy";
private static final String COMPRESSION = "compression";
+ private static final String LOG_CONFIG_OPTION = "log-config";
private final CommandLine arguments;
@@ -205,6 +206,8 @@ class CliArguments {
}
}
+ Optional<Path> logConfigFile() throws CliArgumentsException { return fileValue(LOG_CONFIG_OPTION); }
+
private OptionalInt intValue(String option) throws CliArgumentsException {
try {
Number number = (Number) arguments.getParsedOptionValue(option);
@@ -373,6 +376,14 @@ class CliArguments {
"Valid arguments are: 'auto' (default), 'none', 'gzip'")
.hasArg()
.type(Compression.class)
+ .build())
+ .addOption(Option.builder()
+ .longOpt(LOG_CONFIG_OPTION)
+ .desc("Specify a path to a Java Util Logging properties file. " +
+ "Overrides the default configuration from " +
+ "VESPA_HOME/conf/vespa-feed-client/logging.properties")
+ .hasArg()
+ .type(File.class)
.build());
}
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
index 8f2a5b4c5a0..9037b453e47 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
@@ -14,6 +14,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -33,6 +34,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.joining;
@@ -44,6 +47,7 @@ import static java.util.stream.Collectors.joining;
*/
public class CliClient {
+ private static final Logger log = Logger.getLogger(CliClient.class.getName());
private static final JsonFactory factory = new JsonFactory().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
private final PrintStream systemOut;
@@ -67,7 +71,16 @@ public class CliClient {
boolean verbose = false;
try {
CliArguments cliArgs = CliArguments.fromRawArgs(rawArgs);
+ var logConfigFile = cliArgs.logConfigFile().orElse(null);
verbose = cliArgs.verboseSpecified();
+ if (logConfigFile != null) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(logConfigFile))) {
+ LogManager.getLogManager().readConfiguration(in);
+ log.fine(() -> "Log configuration overridden by " + logConfigFile);
+ } catch (IOException e) {
+ return handleException(verbose, "Failed to read log configuration from " + logConfigFile, e);
+ }
+ }
if (cliArgs.helpSpecified()) {
cliArgs.printHelp(systemOut);
return 0;
diff --git a/vespa-feed-client-cli/src/test/resources/help.txt b/vespa-feed-client-cli/src/test/resources/help.txt
index 554c42af3dc..8e34c61c0f2 100644
--- a/vespa-feed-client-cli/src/test/resources/help.txt
+++ b/vespa-feed-client-cli/src/test/resources/help.txt
@@ -23,6 +23,12 @@ Vespa feed client
--header <arg> HTTP header on the form 'Name:
value'
--help
+ --log-config <arg> Specify a path to a Java Util
+ Logging properties file.
+ Overrides the default
+ configuration from
+ VESPA_HOME/conf/vespa-feed-clien
+ t/logging.properties
--max-failure-seconds <arg> Exit if specified number of
seconds ever pass without any
successful operations. Disabled