Skip to content

Commit

Permalink
[slf4j-maven] Refactor the logger for removing deprecated SLF4J API.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 5, 2019
1 parent 42f8dd7 commit cced9e7
Showing 1 changed file with 48 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.text.MessageFormat;

import org.apache.maven.plugin.logging.Log;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.Marker;
import org.slf4j.event.Level;
import org.slf4j.helpers.LegacyAbstractLogger;

/** Apache logger that is wrapping a Maven logger.
*
Expand All @@ -33,9 +35,9 @@
* @mavenartifactid $ArtifactId$
* @since 16.0
*/
public class MavenSlf4jLogger extends MarkerIgnoringBase {
public class MavenSlf4jLogger extends LegacyAbstractLogger {

private static final long serialVersionUID = 937126994481217789L;
private static final long serialVersionUID = -5538811471324622933L;

private final Log mavenLogger;

Expand All @@ -54,149 +56,70 @@ public boolean isTraceEnabled() {
return this.mavenLogger.isDebugEnabled();
}

@Override
public void trace(String msg) {
this.mavenLogger.debug(msg);
}

@Override
public void trace(String format, Object arg) {
this.mavenLogger.debug(MessageFormat.format(format, arg));
}

@Override
public void trace(String format, Object arg1, Object arg2) {
this.mavenLogger.debug(MessageFormat.format(format, arg1, arg2));
}

@Override
public void trace(String format, Object... arguments) {
this.mavenLogger.debug(MessageFormat.format(format, arguments));
}

@Override
public void trace(String msg, Throwable t) {
this.mavenLogger.debug(msg, t);
}

@Override
public boolean isDebugEnabled() {
return this.mavenLogger.isDebugEnabled();
}

@Override
public void debug(String msg) {
this.mavenLogger.debug(msg);
}

@Override
public void debug(String format, Object arg) {
this.mavenLogger.debug(MessageFormat.format(format, arg));
}

@Override
public void debug(String format, Object arg1, Object arg2) {
this.mavenLogger.debug(MessageFormat.format(format, arg1, arg2));
}

@Override
public void debug(String format, Object... arguments) {
this.mavenLogger.debug(MessageFormat.format(format, arguments));
}

@Override
public void debug(String msg, Throwable t) {
this.mavenLogger.debug(msg, t);
}

@Override
public boolean isInfoEnabled() {
return this.mavenLogger.isInfoEnabled();
}

@Override
public void info(String msg) {
this.mavenLogger.info(msg);
}

@Override
public void info(String format, Object arg) {
this.mavenLogger.info(MessageFormat.format(format, arg));
}

@Override
public void info(String format, Object arg1, Object arg2) {
this.mavenLogger.info(MessageFormat.format(format, arg1, arg2));
}

@Override
public void info(String format, Object... arguments) {
this.mavenLogger.info(MessageFormat.format(format, arguments));
}

@Override
public void info(String msg, Throwable t) {
this.mavenLogger.info(msg, t);
}

@Override
public boolean isWarnEnabled() {
return this.mavenLogger.isWarnEnabled();
}

@Override
public void warn(String msg) {
this.mavenLogger.warn(msg);
}

@Override
public void warn(String format, Object arg) {
this.mavenLogger.warn(MessageFormat.format(format, arg));
}

@Override
public void warn(String format, Object... arguments) {
this.mavenLogger.warn(MessageFormat.format(format, arguments));
}

@Override
public void warn(String format, Object arg1, Object arg2) {
this.mavenLogger.warn(MessageFormat.format(format, arg1, arg2));
}

@Override
public void warn(String msg, Throwable t) {
this.mavenLogger.warn(msg, t);
}

@Override
public boolean isErrorEnabled() {
return this.mavenLogger.isErrorEnabled();
}

@Override
public void error(String msg) {
this.mavenLogger.error(msg);
}

@Override
public void error(String format, Object arg) {
this.mavenLogger.error(MessageFormat.format(format, arg));
}

@Override
public void error(String format, Object arg1, Object arg2) {
this.mavenLogger.error(MessageFormat.format(format, arg1, arg2));
}

@Override
public void error(String format, Object... arguments) {
this.mavenLogger.error(MessageFormat.format(format, arguments));
}

@Override
public void error(String msg, Throwable t) {
this.mavenLogger.error(msg, t);
protected String getFullyQualifiedCallerName() {
return null;
}

@Override
protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] arguments,
Throwable throwable) {
final String expandedMessage = MessageFormat.format(msg, arguments);
if (level != null) {
switch (level) {
case INFO:
if (throwable != null) {
this.mavenLogger.info(expandedMessage, throwable);
} else {
this.mavenLogger.info(expandedMessage);
}
break;
case WARN:
if (throwable != null) {
this.mavenLogger.warn(expandedMessage, throwable);
} else {
this.mavenLogger.warn(expandedMessage);
}
break;
case ERROR:
if (throwable != null) {
this.mavenLogger.error(expandedMessage, throwable);
} else {
this.mavenLogger.error(expandedMessage);
}
break;
case DEBUG:
case TRACE:
if (throwable != null) {
this.mavenLogger.debug(expandedMessage, throwable);
} else {
this.mavenLogger.debug(expandedMessage);
}
break;
default:
break;
}
}
}

}

0 comments on commit cced9e7

Please sign in to comment.