From 83b34f2384a243034e36493727a9650d0245878d Mon Sep 17 00:00:00 2001 From: Hendrik Ebbers Date: Sun, 28 Apr 2024 09:35:37 -0500 Subject: [PATCH] Big refactoring of logging benchmarks Signed-off-by: Hendrik Ebbers --- .../SwirldsLoggingConfigFactory.java | 6 +- .../swirldslog/plain/SwirldsLogConfig.java | 99 ----------------- .../rolling/RollingSwirldsLogConfig.java | 103 ------------------ 3 files changed, 5 insertions(+), 203 deletions(-) delete mode 100644 platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/plain/SwirldsLogConfig.java delete mode 100644 platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/rolling/RollingSwirldsLogConfig.java diff --git a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/SwirldsLoggingConfigFactory.java b/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/SwirldsLoggingConfigFactory.java index fbe6a5fd71f1..6a44f31f95fa 100644 --- a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/SwirldsLoggingConfigFactory.java +++ b/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/SwirldsLoggingConfigFactory.java @@ -18,6 +18,8 @@ import com.swirlds.config.api.Configuration; import com.swirlds.logging.api.internal.LoggingSystem; +import com.swirlds.logging.api.internal.configuration.ConfigLevelConverter; +import com.swirlds.logging.api.internal.configuration.MarkerStateConverter; import com.swirlds.logging.benchmark.config.AppenderType; import com.swirlds.logging.benchmark.config.Constants; import com.swirlds.logging.benchmark.config.LoggingBenchmarkConfig; @@ -38,7 +40,9 @@ public LoggingSystem createLoggingSystem(@NonNull final LoggingBenchmarkConfig c private static Configuration createConfiguration(@NonNull final LoggingBenchmarkConfig config) { com.swirlds.config.api.ConfigurationBuilder configurationBuilder = com.swirlds.config.api.ConfigurationBuilder.create(); - configurationBuilder = configurationBuilder.withValue("logging.level", "trace"); + configurationBuilder = configurationBuilder.withValue("logging.level", "trace") + .withConverter(new ConfigLevelConverter()) + .withConverter(new MarkerStateConverter()); if (config.forwardToSwirldsLogging()) { configurationBuilder = configurationBuilder.withValue("logging.provider.log4j.enabled", "true"); diff --git a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/plain/SwirldsLogConfig.java b/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/plain/SwirldsLogConfig.java deleted file mode 100644 index 1af1db46a1db..000000000000 --- a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/plain/SwirldsLogConfig.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2024 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.swirlds.logging.benchmark.swirldslog.plain; - -import com.swirlds.config.api.Configuration; -import com.swirlds.config.api.ConfigurationBuilder; -import com.swirlds.logging.api.internal.LoggingSystem; -import com.swirlds.logging.api.internal.configuration.ConfigLevelConverter; -import com.swirlds.logging.api.internal.configuration.MarkerStateConverter; -import com.swirlds.logging.benchmark.config.LoggingBenchmarkConfigProvider; -import com.swirlds.logging.benchmark.util.ConfigManagement; -import edu.umd.cs.findbugs.annotations.NonNull; - -/** - * Convenience methods for configuring swirlds-logging logger - */ -public class SwirldsLogConfig implements LoggingBenchmarkConfigProvider { - - /** - * {@inheritDoc} - * @param logFile - */ - public @NonNull LoggingSystem configureFileLogging(final String logFile) { - final com.swirlds.config.api.Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.file.type", "file") - .withValue("logging.handler.file.enabled", "true") - .withValue("logging.handler.file.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.file.level", "trace") - .withValue("logging.handler.file.file", logFile) - .build(); - - return configure(configuration); - } - - /** - * {@inheritDoc} - */ - public @NonNull LoggingSystem configureConsoleLogging() { - final com.swirlds.config.api.Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.console.type", "console") - .withValue("logging.handler.console.enabled", "true") - .withValue("logging.handler.console.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.console.level", "trace") - .build(); - - return configure(configuration); - } - - /** - * {@inheritDoc} - * @param logFile - */ - public @NonNull LoggingSystem configureFileAndConsoleLogging(final String logFile) { - final com.swirlds.config.api.Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.file.type", "file") - .withValue("logging.handler.file.enabled", "true") - .withValue("logging.handler.file.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.file.level", "trace") - .withValue("logging.handler.file.file", logFile) - .withValue("logging.handler.console.type", "console") - .withValue("logging.handler.console.enabled", "true") - .withValue("logging.handler.console.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.console.level", "trace") - .build(); - - return configure(configuration); - } - - @NonNull - private LoggingSystem configure(@NonNull final Configuration configuration) { - LoggingSystem loggingSystem = new LoggingSystem(configuration); - loggingSystem.installHandlers(); - loggingSystem.installProviders(); - return loggingSystem; - } -} diff --git a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/rolling/RollingSwirldsLogConfig.java b/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/rolling/RollingSwirldsLogConfig.java deleted file mode 100644 index 2abccf66e052..000000000000 --- a/platform-sdk/swirlds-logging/src/jmh/java/com/swirlds/logging/benchmark/swirldslog/rolling/RollingSwirldsLogConfig.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2024 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.swirlds.logging.benchmark.swirldslog.rolling; - -import com.swirlds.config.api.Configuration; -import com.swirlds.config.api.ConfigurationBuilder; -import com.swirlds.logging.api.internal.LoggingSystem; -import com.swirlds.logging.api.internal.configuration.ConfigLevelConverter; -import com.swirlds.logging.api.internal.configuration.MarkerStateConverter; -import com.swirlds.logging.benchmark.config.LoggingBenchmarkConfigProvider; -import com.swirlds.logging.benchmark.util.ConfigManagement; -import edu.umd.cs.findbugs.annotations.NonNull; - -/** - * Convenience methods for configuring swirlds-logging logger - */ -public class RollingSwirldsLogConfig implements LoggingBenchmarkConfigProvider { - - /** - * {@inheritDoc} - * @param logFile - */ - public @NonNull LoggingSystem configureFileLogging(final String logFile) { - final Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.file.type", "file") - .withValue("logging.handler.file.enabled", "true") - .withValue("logging.handler.file.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.file.level", "trace") - .withValue("logging.handler.file.file", logFile) - .withValue("logging.handler.file.file-rolling.maxFileSize", "500MB") - .withValue("logging.handler.file.file-rolling.maxRollover", "1") - .build(); - - return configure(configuration); - } - - /** - * {@inheritDoc} - */ - public @NonNull LoggingSystem configureConsoleLogging() { - final Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.console.type", "console") - .withValue("logging.handler.console.enabled", "true") - .withValue("logging.handler.console.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.console.level", "trace") - .build(); - - return configure(configuration); - } - - /** - * {@inheritDoc} - * @param logFile - */ - public @NonNull LoggingSystem configureFileAndConsoleLogging(final String logFile) { - final Configuration configuration = ConfigurationBuilder.create() - .withConverter(new ConfigLevelConverter()) - .withConverter(new MarkerStateConverter()) - .withValue("logging.level", "trace") - .withValue("logging.handler.file.type", "file") - .withValue("logging.handler.file.enabled", "true") - .withValue("logging.handler.file.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.file.level", "trace") - .withValue("logging.handler.file.file", logFile) - .withValue("logging.handler.console.type", "console") - .withValue("logging.handler.console.enabled", "true") - .withValue("logging.handler.console.formatTimestamp", ConfigManagement.formatTimestamp() + "") - .withValue("logging.handler.file.file-rolling.maxFileSize", "30MB") - .withValue("logging.handler.file.file-rolling.maxRollover", "1") - .withValue("logging.handler.console.level", "trace") - .build(); - - return configure(configuration); - } - - @NonNull - private LoggingSystem configure(@NonNull final Configuration configuration) { - LoggingSystem loggingSystem = new LoggingSystem(configuration); - loggingSystem.installHandlers(); - loggingSystem.installProviders(); - return loggingSystem; - } -}