Skip to content

Commit

Permalink
Refactor CRDGeneratorCLI to use log4j
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed Oct 10, 2024
1 parent fb99c46 commit f952069
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
12 changes: 10 additions & 2 deletions crd-generator/cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<!-- required because parent pom declares default scope to test -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<!-- required because parent pom declares default scope to test -->
<scope>compile</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package io.fabric8.crd.generator.cli;

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

import java.util.List;

Expand All @@ -34,15 +33,13 @@ static void configureLogger(List<Boolean> verbose) {
}

private static void configureLogger(LogLevel baseLogLevel) {
setLogLevel("io.fabric8.crd.generator.cli", baseLogLevel.toLogbackLevel());
setLogLevel("io.fabric8.crd.generator.collector", baseLogLevel.toLogbackLevel());
setLogLevel("io.fabric8.crdv2.generator", baseLogLevel.toLogbackLevel());
setLogLevel("io.fabric8.crd.generator.cli", baseLogLevel.toLog4jLevel());
setLogLevel("io.fabric8.crd.generator.collector", baseLogLevel.toLog4jLevel());
setLogLevel("io.fabric8.crdv2.generator", baseLogLevel.toLog4jLevel());
}

private static void setLogLevel(String packageName, Level level) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger logger = loggerContext.getLogger(packageName);
logger.setLevel(level);
Configurator.setLevel(packageName, level);
}

/**
Expand Down Expand Up @@ -71,8 +68,8 @@ enum LogLevel {
DEBUG,
TRACE;

Level toLogbackLevel() {
return Level.toLevel(name());
Level toLog4jLevel() {
return Level.valueOf(name());
}
}
}
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<jackson.bundle.version>${jackson.version}</jackson.bundle.version>
<slf4j.version>2.0.16</slf4j.version>
<log4j.version>2.24.1</log4j.version>
<logback.version>1.3.14</logback.version>
<lombok.version>1.18.34</lombok.version>
<snakeyaml.version>2.8</snakeyaml.version>
<snakeyaml.bundle.version>2.2</snakeyaml.bundle.version> <!-- Transitive Jackson -->
Expand Down Expand Up @@ -861,11 +860,6 @@
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand Down

0 comments on commit f952069

Please sign in to comment.