Skip to content

Commit

Permalink
add debug logging with slf4j.Logger for mvn -X
Browse files Browse the repository at this point in the history
allow e.g. maven (which also uses Slf4j) to see / capture resolver debug log output e.g. when running mvn -X clean install

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed May 13, 2024
1 parent 32e6b2e commit 1db5a87
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion biz.aQute.resolve/src/biz/aQute/resolve/ResolverLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import aQute.bnd.exceptions.Exceptions;
import aQute.bnd.osgi.Constants;
Expand All @@ -19,6 +21,8 @@

public class ResolverLogger implements LogService, AutoCloseable {

private static final Logger logger = LoggerFactory.getLogger(ResolverLogger.class);

public static final int DEFAULT_LEVEL = 4;

public static final int LOG_ERROR = 1;
Expand Down Expand Up @@ -56,6 +60,7 @@ public ResolverLogger(int level, PrintStream out) {
printer = IO.writer(out, UTF_8);
}


@Override
public void log(int level, String msg, Throwable throwable) {
switch (level) {
Expand All @@ -68,6 +73,7 @@ public void log(int level, String msg, Throwable throwable) {
printLog(msg, throwable);
if (throwable != null) {
throwable.printStackTrace(printer);
logger.debug("", throwable);
}
break;
case LOG_INFO :
Expand All @@ -91,10 +97,13 @@ public void log(int level, String msg, Throwable throwable) {

private void printLog(String msg, Throwable throwable) {
printer.print(msg);
logger.debug(msg);
if (throwable != null) {
printer.print(" (");
printer.print(throwable);
printer.print(")");

logger.debug("({})", String.valueOf(throwable));
}
printer.println();
}
Expand Down Expand Up @@ -203,7 +212,7 @@ public static ResolverLogger newLogger(Processor processor, boolean keepLogFileT
logger.setKeepLogFileTillExit(keepLogFileTillJvmExit);
return logger;
}
ResolverLogger logger = new ResolverLogger();
ResolverLogger logger = new ResolverLogger(DEFAULT_LEVEL);
logger.setKeepLogFileTillExit(keepLogFileTillJvmExit);
return logger;
} catch (Exception e) {
Expand Down

0 comments on commit 1db5a87

Please sign in to comment.