From b373c30f41d33ee1fb65be045182aa59871eecac Mon Sep 17 00:00:00 2001 From: Matt Peterson Date: Tue, 3 Sep 2024 09:52:01 -0600 Subject: [PATCH] feat: added logging.properties and gradle config to enable Helidon logging Signed-off-by: Matt Peterson --- gradle/modules.properties | 2 ++ server/build.gradle.kts | 1 + server/docker/Dockerfile | 3 ++ server/docker/logging.properties | 32 +++++++++++++++++++ .../com/hedera/block/server/Constants.java | 6 ++++ .../java/com/hedera/block/server/Server.java | 17 ++++++++-- server/src/main/java/module-info.java | 1 + settings.gradle.kts | 1 + 8 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 server/docker/logging.properties diff --git a/gradle/modules.properties b/gradle/modules.properties index bff4c00ca..8290bd368 100644 --- a/gradle/modules.properties +++ b/gradle/modules.properties @@ -12,6 +12,8 @@ com.lmax.disruptor=com.lmax:disruptor io.helidon.webserver=io.helidon.webserver:helidon-webserver io.helidon.webserver.grpc=io.helidon.webserver:helidon-webserver-grpc io.helidon.webserver.testing.junit5=io.helidon.webserver.testing.junit5:helidon-webserver-testing-junit5 + +io.helidon.logging=io.helidon.logging:helidon-logging-jul org.antlr.antlr4.runtime=org.antlr:antlr4-runtime com.google.common=com.google.guava:guava diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 7bd255538..322e4b970 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -29,6 +29,7 @@ mainModuleInfo { annotationProcessor("com.google.auto.service.processor") runtimeOnly("com.swirlds.config.impl") runtimeOnly("org.apache.logging.log4j.slf4j2.impl") + runtimeOnly("io.helidon.logging") } testModuleInfo { diff --git a/server/docker/Dockerfile b/server/docker/Dockerfile index 693784aa1..50b1c5ad4 100644 --- a/server/docker/Dockerfile +++ b/server/docker/Dockerfile @@ -24,5 +24,8 @@ COPY --from=distributions server-${VERSION}.tar . # Extract the TAR file RUN tar -xvf server-${VERSION}.tar +# Copy the logging properties file +COPY logging.properties logging.properties + # RUN the bin script for starting the server ENTRYPOINT ["/bin/bash", "-c", "/app/server-${VERSION}/bin/server"] diff --git a/server/docker/logging.properties b/server/docker/logging.properties new file mode 100644 index 000000000..91d8f4419 --- /dev/null +++ b/server/docker/logging.properties @@ -0,0 +1,32 @@ +# Log Level Values +# +# SEVERE: indicates a critical error or failure +# WARNING: warns of potential issues or errors +# INFO: reports normal operational information +# CONFIG: provides configuration-related information +# FINE: provides detailed debugging information +# FINER: provides finer-grained debugging information +# FINEST: provides the most detailed debugging information + +# Set the default logging level +.level=INFO + +# Helidon loggers +io.helidon.webserver.level=SEVERE +io.helidon.config.level=SEVERE +io.helidon.security.level=INFO +io.helidon.common.level=INFO + +# Configure the app log level +#com.hedera.block.level=FINE +#com.hedera.block.server.level=FINE + +# Configure specific loggers +#com.hedera.block.server.mediator.LiveStreamMediatorImpl.level=FINE +#com.hedera.block.server.persistence.storage.write.BlockAsDirWriter.level=FINE +#com.hedera.block.server.producer.ProducerBlockItemObserver.level=FINE + +# Console handler configuration +handlers = java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level = FINE +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter diff --git a/server/src/main/java/com/hedera/block/server/Constants.java b/server/src/main/java/com/hedera/block/server/Constants.java index 8fbd69005..9f12b5948 100644 --- a/server/src/main/java/com/hedera/block/server/Constants.java +++ b/server/src/main/java/com/hedera/block/server/Constants.java @@ -25,6 +25,12 @@ private Constants() {} /** Constant mapped to the application.properties file in resources with default values */ @NonNull public static final String APPLICATION_PROPERTIES = "app.properties"; + /** + * Constant mapped to the Helidon logging.properties file in the docker directory with default + * values. + */ + @NonNull public static final String LOGGING_PROPERTIES = "logging.properties"; + /** Constant mapped to the name of the service in the .proto file */ @NonNull public static final String SERVICE_NAME = "BlockStreamService"; diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index 48b394902..1365bac7c 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -16,6 +16,9 @@ package com.hedera.block.server; +import static com.hedera.block.server.Constants.APPLICATION_PROPERTIES; +import static com.hedera.block.server.Constants.LOGGING_PROPERTIES; +import static io.helidon.config.ConfigSources.file; import static java.lang.System.Logger; import static java.lang.System.Logger.Level.INFO; @@ -24,8 +27,10 @@ import com.swirlds.config.extensions.sources.ClasspathFileConfigSource; import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource; import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource; +import io.helidon.config.Config; import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; /** Main class for the block node server */ public class Server { @@ -43,14 +48,20 @@ private Server() {} public static void main(final String[] args) throws IOException { LOGGER.log(INFO, "Starting BlockNode Server"); + // Set the global configuration + final Config config = + Config.builder() + .sources(file(Paths.get("/app", LOGGING_PROPERTIES)).optional()) + .build(); + + Config.global(config); + // Init BlockNode Configuration Configuration configuration = ConfigurationBuilder.create() .withSource(SystemEnvironmentConfigSource.getInstance()) .withSource(SystemPropertiesConfigSource.getInstance()) - .withSource( - new ClasspathFileConfigSource( - Path.of(Constants.APPLICATION_PROPERTIES))) + .withSources(new ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES))) .autoDiscoverExtensions() .build(); diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 4a938f307..633524672 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -26,6 +26,7 @@ requires dagger; requires io.grpc.stub; requires io.helidon.common; + requires io.helidon.config; requires io.helidon.webserver.grpc; requires io.helidon.webserver; requires javax.inject; diff --git a/settings.gradle.kts b/settings.gradle.kts index b195e4fa2..4770f3462 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -44,6 +44,7 @@ dependencyResolutionManagement { // Compile time dependencies version("io.helidon.webserver.http2", "4.1.0") version("io.helidon.webserver.grpc", "4.1.0") + version("io.helidon.logging", "4.1.0") version("com.lmax.disruptor", "4.0.0") version("com.github.spotbugs.annotations", "4.7.3") version("com.swirlds.metrics.api", swirldsVersion)