Skip to content

Commit

Permalink
replace log4j with slf4j and logback
Browse files Browse the repository at this point in the history
unfortunately spring-boot hard code support for an older slf4j and logback, but this is isolated in scenario
  • Loading branch information
cwensel committed Jan 15, 2025
1 parent f420648 commit 15fd2a0
Show file tree
Hide file tree
Showing 59 changed files with 210 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
*/

plugins {
// Apply the common convention plugin for shared build configuration between library and application projects.
id("clusterless.java-common-conventions")

// Apply the application plugin to add support for building a CLI application in Java.
application
}

dependencies {
implementation("info.picocli:picocli")
implementation("com.github.jknack:handlebars")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("ch.qos.logback:logback-core")
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ fun DependencyConstraintHandlerScope.testImplementationAndTestFixture(constraint
}

dependencies {
implementation("org.apache.logging.log4j:log4j-api")
implementation("org.apache.logging.log4j:log4j-core")
implementation("org.apache.logging.log4j:log4j-jul")
implementation("org.slf4j:slf4j-api")

implementation("org.jetbrains:annotations")

compileOnly("javax.annotation:javax.annotation-api")
Expand All @@ -110,6 +109,13 @@ dependencies {
implementation("com.github.jknack:handlebars:4.4.0")
// implementation("com.cronutils:cron-utils:9.2.0")

val slf4j = "2.0.16"
implementation("org.slf4j:slf4j-api:$slf4j")
val logback = "1.5.16"
implementation("ch.qos.logback:logback-classic:$logback")
implementation("ch.qos.logback:logback-core:$logback")

// only used by lambdas
// https://mvnrepository.com/artifact/org.apache.logging.log4j
val log4j = "2.24.3"
implementation("org.apache.logging.log4j:log4j-api:$log4j")
Expand Down Expand Up @@ -181,7 +187,8 @@ dependencies {
// https://github.com/testcontainers/testcontainers-java/issues/1442#issuecomment-694342883
testImplementationAndTestFixture("com.amazonaws:aws-java-sdk-s3:1.11.860")

testImplementationAndTestFixture("org.apache.logging.log4j:log4j-slf4j-impl:$log4j")
testImplementationAndTestFixture("ch.qos.logback:logback-classic:$logback")
testImplementationAndTestFixture("ch.qos.logback:logback-core:$logback")
}
}

Expand All @@ -203,8 +210,6 @@ testing {
implementation("uk.org.webcompere:system-stubs-core")
implementation("uk.org.webcompere:system-stubs-jupiter")
implementation("org.mockito:mockito-inline")

implementation("org.apache.logging.log4j:log4j-slf4j-impl") // used by inject-resources
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import gradle.kotlin.dsl.accessors._4c82c8048bcef42aad7cd4b7a363d7d5.implementation

/*
* Copyright (c) 2023-2025 Chris K Wensel <[email protected]>. All Rights Reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

plugins {
id("clusterless.java-common-conventions")
`java-library`
}

dependencies {
implementation("org.apache.logging.log4j:log4j-slf4j-impl")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

plugins {
// Apply the common convention plugin for shared build configuration between library and application projects.
id("clusterless.java-common-conventions")

// Apply the java-library plugin for API and implementation separation.
`java-library`
}

dependencies {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.toml.TomlMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Files;
Expand All @@ -37,7 +37,7 @@
*
*/
public class ConfigManager {
private static final Logger LOG = LogManager.getLogger(ConfigManager.class);
private static final Logger LOG = LoggerFactory.getLogger(ConfigManager.class);
public static final Path CURRENT_DIR = Paths.get(".").toAbsolutePath().normalize();
public static final Path HOME_DIR = Paths.get(System.getProperty("user.home")).toAbsolutePath().normalize();
public static final Path GLOBAL_CONFIG_DIR = HOME_DIR.resolve(Paths.get(".cls"));
Expand Down
2 changes: 2 additions & 0 deletions clusterless-main-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies {
implementation(project(":clusterless-common"))
implementation(project(":clusterless-model"))

compileOnly("ch.qos.logback:logback-classic")

implementation("io.heretical:mini-parsers-temporal")
implementation("info.picocli:picocli")
implementation("com.github.jknack:handlebars")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
import io.github.resilience4j.retry.MaxRetriesExceededException;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.time.Duration;
import java.util.*;
import java.util.function.Supplier;

public abstract class ProcessExec {
private static final Logger LOG = LogManager.getLogger(ProcessExec.class);
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ProcessExec.class);
protected Supplier<Boolean> dryRun = () -> false;
protected Supplier<Boolean> retry = () -> false;
protected Supplier<Integer> verbosity = () -> 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

package clusterless.cls.startup;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import static org.slf4j.Logger.ROOT_LOGGER_NAME;

/**
* https://picocli.info/#_use_case_configure_log_level_with_a_global_option
*/
Expand All @@ -23,7 +26,8 @@ public class Verbosity {
private int level = 0;

public static void setLoggingLevel(Level level) {
Configurator.setRootLevel(level);
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.getLogger(ROOT_LOGGER_NAME).setLevel(level);
}

public static void disable() {
Expand Down
5 changes: 2 additions & 3 deletions clusterless-main/src/main/java/clusterless/cls/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
import clusterless.cls.util.ExitCodeExceptionMapper;
import clusterless.cls.util.ParameterExceptionHandler;
import clusterless.cls.util.VersionProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.io.IOException;
Expand Down Expand Up @@ -64,7 +63,7 @@
}
)
public class Main extends Startup implements Callable<Integer> {
private static final Logger LOG = LogManager.getLogger(Main.class);
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(Main.class);

/**
* This provides a global --providers predicate, but when calling a provider, we need to sort out a way
Expand Down
23 changes: 0 additions & 23 deletions clusterless-main/src/main/resources/log4j2.xml

This file was deleted.

19 changes: 19 additions & 0 deletions clusterless-main/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%yellow(%d{HH:mm:ss.SSS}) %highlight(%-5level){FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green}
%msg%n
</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import clusterless.cls.model.deploy.Deployable;
import clusterless.cls.model.deploy.Extensible;
import clusterless.cls.util.Annotations;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
*
*/
public class ComponentServices {
private static final Logger LOG = LogManager.getLogger(ComponentServices.class);
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ComponentServices.class);

public static final ComponentServices INSTANCE = new ComponentServices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import clusterless.cls.model.deploy.*;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -26,7 +25,7 @@
* to declare read permissions against datasets they do not own.
*/
public class DatasetResolver {
private static final Logger LOG = LogManager.getLogger(DatasetResolver.class);
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(DatasetResolver.class);
private final List<Deployable> deployables;
private final Map<Placement, Map<ReferencedDataset, OwnedDataset>> resolved = new HashMap<>();
private final RemoteDatasetOwnerLookup remoteLookup;
Expand Down
18 changes: 15 additions & 3 deletions clusterless-scenario/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {

implementation("javax.validation:validation-api:2.0.1.Final")

val springBoot = "2.7.3"
val springBoot = "2.7.18"
implementation("org.springframework.boot:spring-boot-starter:$springBoot") {
exclude("org.springframework.boot", "spring-boot-starter-logging")
}
Expand All @@ -73,13 +73,25 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator:$springBoot")
implementation("org.springframework.retry:spring-retry:1.3.3") // 2.0.1 is on jdk 17

implementation("org.apache.logging.log4j:log4j-web")

runtimeOnly("org.glassfish.jaxb:jaxb-runtime:2.3.3")

implementation("com.google.guava:guava")
}

// the current version of spring boot, used by conductor, hard codes a dependency on
// org.slf4j.impl.StaticLoggerBinder in the LogbackLoggingSystem class.
// this was removed in recent slf4j/logback releases so we must pin the scenario project
// to older versions of slf4j/logback
configurations.all {
resolutionStrategy {
force(
"org.slf4j:slf4j-api:1.7.28",
"ch.qos.logback:logback-classic:1.2.11",
"ch.qos.logback:logback-core:1.2.11"
)
}
}

application {
applicationName = "cls-scenario"
mainClass.set("clusterless.scenario.Main")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import clusterless.scenario.model.Scenario;
import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.common.run.Workflow;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import picocli.CommandLine;

Expand All @@ -43,7 +43,7 @@
}
)
public class Main implements Callable<Integer> {
private static final Logger LOG = LogManager.getLogger(Main.class);
private static final Logger LOG = LoggerFactory.getLogger(Main.class);

private ConfigurableApplicationContext server;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

package clusterless.scenario.conductor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
Expand All @@ -19,7 +19,7 @@
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ComponentScan(basePackages = {"com.netflix.conductor", "io.orkes.conductor"})
public class ConductorApp {
private static final Logger LOG = LogManager.getLogger(ConductorApp.class);
private static final Logger LOG = LoggerFactory.getLogger(ConductorApp.class);

public static ConfigurableApplicationContext run(String... args) {
LOG.info("Starting Conductor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class BootstrapRunner {
private static final Logger LOG = LogManager.getLogger(BootstrapRunner.class);
private static final Logger LOG = LoggerFactory.getLogger(BootstrapRunner.class);
private final Options options;
private final WorkflowManager workflowManager;
private final Map<String, String> placement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
import com.netflix.conductor.sdk.workflow.def.tasks.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class ScenarioRunner {
private static final Logger LOG = LogManager.getLogger(ScenarioRunner.class);
private static final Logger LOG = LoggerFactory.getLogger(ScenarioRunner.class);
private final Options options;
private final WorkflowManager workflowManager;
private final Scenario scenario;
Expand Down
Loading

0 comments on commit 15fd2a0

Please sign in to comment.