Skip to content

Commit

Permalink
#22 one access point
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 12, 2022
1 parent b25fc61 commit b0124fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/jcabi/slf4j/JcabiLoggers.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ public void setMavenLog(final Log log) {
}
}

/**
* Get Maven log.
* @return The log
*/
public Log getMavenLog() {
return this.mlog;
}

}
20 changes: 2 additions & 18 deletions src/main/java/com/jcabi/slf4j/MavenSlf4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.maven.plugin.logging.Log;
import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
import org.slf4j.helpers.BasicMDCAdapter;
import org.slf4j.helpers.BasicMarkerFactory;
import org.slf4j.impl.StaticLoggerBinder;
import org.slf4j.spi.MDCAdapter;
import org.slf4j.spi.SLF4JServiceProvider;

Expand All @@ -57,21 +57,14 @@ public final class MavenSlf4j implements SLF4JServiceProvider {
@SuppressWarnings("PMD.LongVariable")
public static final String REQUESTED_API_VERSION = "2.0.99";

/**
* The {@link ILoggerFactory} instance returned by the
* {@link #getLoggerFactory()} method should always be
* the same object.
*/
private static final JcabiLoggers LOGGERS = new JcabiLoggers();

@Override
public void initialize() {
// nothing here
}

@Override
public ILoggerFactory getLoggerFactory() {
return MavenSlf4j.LOGGERS;
return StaticLoggerBinder.getSingleton().getLoggerFactory();
}

@Override
Expand All @@ -89,13 +82,4 @@ public String getRequestedApiVersion() {
return MavenSlf4j.REQUESTED_API_VERSION;
}

/**
* Set Maven Log.
* @param log The log from Maven plugin
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static void setMavenLog(final Log log) {
MavenSlf4j.LOGGERS.setMavenLog(log);
}

}
12 changes: 11 additions & 1 deletion src/main/java/org/slf4j/impl/StaticLoggerBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public final class StaticLoggerBinder implements LoggerFactoryBinder {
* The {@link ILoggerFactory} instance returned by the
* {@link #getLoggerFactory()} method should always be
* the same object.
*
* @checkstyle VisibilityModifierCheck (5 lines)
*/
private final transient JcabiLoggers loggers = new JcabiLoggers();
public final transient JcabiLoggers loggers = new JcabiLoggers();

/**
* Private ctor to avoid direct instantiation of the class.
Expand All @@ -107,6 +109,14 @@ public void setMavenLog(final Log log) {
this.loggers.setMavenLog(log);
}

/**
* Get Maven Log.
* @return The log
*/
public Log getMavenLog() {
return this.loggers.getMavenLog();
}

@Override
public ILoggerFactory getLoggerFactory() {
return this.loggers;
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/jcabi/slf4j/JcabiLoggersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.impl.StaticLoggerBinder;

/**
* Test case for {@link JcabiLoggers}.
Expand All @@ -48,7 +49,7 @@ public final class JcabiLoggersTest {
@BeforeAll
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static void init() {
MavenSlf4j.setMavenLog(
StaticLoggerBinder.getSingleton().setMavenLog(
new DefaultLog(
new ConsoleLogger(
Logger.LEVEL_DEBUG,
Expand Down

0 comments on commit b0124fa

Please sign in to comment.