diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2021-01-19 10:53:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 10:53:00 +0100 |
commit | 677a35028b3aac1b6b7232b470d1fdf2df772a52 (patch) | |
tree | 8cfbd9a6e06089912a0d960fcd66687ce65f744d /jdisc_http_service/src/main | |
parent | 4862320dd1e85efa4e48f8faa3ab2e11684d6b70 (diff) | |
parent | 5d53a6fa04da4b5e92778a3b885d6a6f1328e37d (diff) |
Merge pull request #16092 from vespa-engine/mortent/connection-log-file
write connection log to file
Diffstat (limited to 'jdisc_http_service/src/main')
4 files changed, 72 insertions, 23 deletions
diff --git a/jdisc_http_service/src/main/java/com/yahoo/container/logging/ConnectionLogHandler.java b/jdisc_http_service/src/main/java/com/yahoo/container/logging/ConnectionLogHandler.java new file mode 100644 index 00000000000..1e64ac1618c --- /dev/null +++ b/jdisc_http_service/src/main/java/com/yahoo/container/logging/ConnectionLogHandler.java @@ -0,0 +1,31 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.container.logging; + +import java.util.logging.Logger; + +/** + * @author mortent + */ +class ConnectionLogHandler { + public final Logger connection = Logger.getAnonymousLogger(); + private final LogFileHandler logFileHandler; + + public ConnectionLogHandler(String clusterName) { + connection.setUseParentHandlers(false); + + logFileHandler = new LogFileHandler(true); + logFileHandler.setFilePattern(String.format("logs/vespa/qrs/connection.%s.%s", clusterName, "%Y%m%d%H%M%S")); + + LogFormatter lf = new LogFormatter(); + lf.messageOnly(true); + this.logFileHandler.setFormatter(lf); + connection.addHandler(this.logFileHandler); + } + + public void shutdown() { + logFileHandler.close(); + connection.removeHandler(logFileHandler); + logFileHandler.shutdown(); + } +}
\ No newline at end of file diff --git a/jdisc_http_service/src/main/java/com/yahoo/container/logging/FileConnectionLog.java b/jdisc_http_service/src/main/java/com/yahoo/container/logging/FileConnectionLog.java new file mode 100644 index 00000000000..16e49730fdd --- /dev/null +++ b/jdisc_http_service/src/main/java/com/yahoo/container/logging/FileConnectionLog.java @@ -0,0 +1,37 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.container.logging; + +import com.google.inject.Inject; +import com.yahoo.component.AbstractComponent; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author mortent + */ +public class FileConnectionLog extends AbstractComponent implements ConnectionLog { + + private static final Logger logger = Logger.getLogger(FileConnectionLog.class.getName()); + private final ConnectionLogHandler logHandler; + + @Inject + public FileConnectionLog(ConnectionLogConfig config) { + logHandler = new ConnectionLogHandler(config.cluster()); + } + + @Override + public void log(ConnectionLogEntry connectionLogEntry) { + try { + logHandler.connection.log(Level.INFO, connectionLogEntry.toJson()); + } catch (Exception e) { + logger.log(Level.WARNING, "Unable to write connection log entry for connection id " + connectionLogEntry.id(), e); + } + } + + @Override + public void deconstruct() { + logHandler.shutdown(); + } +}
\ No newline at end of file diff --git a/jdisc_http_service/src/main/java/com/yahoo/container/logging/SimpleConnectionLog.java b/jdisc_http_service/src/main/java/com/yahoo/container/logging/SimpleConnectionLog.java deleted file mode 100644 index ea6db42aa16..00000000000 --- a/jdisc_http_service/src/main/java/com/yahoo/container/logging/SimpleConnectionLog.java +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -package com.yahoo.container.logging; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author mortent - */ -public class SimpleConnectionLog implements ConnectionLog { - - private static final Logger logger = Logger.getLogger(SimpleConnectionLog.class.getName()); - - @Override - public void log(ConnectionLogEntry connectionLogEntry) { - try { - System.out.println(connectionLogEntry.toJson()); - } catch (Exception e) { - logger.log(Level.WARNING, "Unable to write connection log entry for connection id " + connectionLogEntry.id(), e); - } - } -} diff --git a/jdisc_http_service/src/main/resources/configdefinitions/container.logging.connection-log.def b/jdisc_http_service/src/main/resources/configdefinitions/container.logging.connection-log.def new file mode 100644 index 00000000000..3a2d49120c9 --- /dev/null +++ b/jdisc_http_service/src/main/resources/configdefinitions/container.logging.connection-log.def @@ -0,0 +1,4 @@ +namespace=container.logging + +# Name of the cluster +cluster string
\ No newline at end of file |