#147 - Polishing.

Improve logger formatting to easier distinguish between log messages indicating Maven start and success.
Avoid duplicate logging of exceptions.
This commit is contained in:
Mark Paluch
2020-06-10 15:34:17 +02:00
parent b065b070d0
commit 2a4a1f50aa
5 changed files with 15 additions and 12 deletions

View File

@@ -88,7 +88,7 @@ class CustomShellComponent extends JLineShellComponent {
ReflectionUtils.makeAccessible(method); ReflectionUtils.makeAccessible(method);
return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments()); return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments());
} catch (Throwable th) { } catch (Throwable th) {
logger.severe("Command failed " + th); logger.severe("Command failed");
return handleThrowable(th); return handleThrowable(th);
} }
} }

View File

@@ -351,7 +351,7 @@ class MavenBuildSystem implements BuildSystem {
Gpg gpg = this.gpg.isGpgAvailable() ? this.gpg : properties.getGpg(); Gpg gpg = this.gpg.isGpgAvailable() ? this.gpg : properties.getGpg();
CommandLine arguments = CommandLine.of(Goal.DEPLOY, // CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.DEPLOY, //
profile("ci,release,central"), // profile("ci,release,central"), //
SKIP_TESTS, // SKIP_TESTS, //
arg("gpg.executable").withValue(gpg.getExecutable()), // arg("gpg.executable").withValue(gpg.getExecutable()), //

View File

@@ -69,7 +69,7 @@ class MavenRuntime {
public void execute(Project project, CommandLine arguments) { public void execute(Project project, CommandLine arguments) {
logger.log(project, "Executing mvn %s", arguments.toString()); logger.log(project, "📦 Executing mvn %s", arguments.toString());
try (MavenLogger mavenLogger = getLogger(project, arguments.getGoals())) { try (MavenLogger mavenLogger = getLogger(project, arguments.getGoals())) {
@@ -94,11 +94,12 @@ class MavenRuntime {
InvocationResult result = invoker.execute(request); InvocationResult result = invoker.execute(request);
if (result.getExitCode() != 0) { if (result.getExitCode() != 0) {
logger.warn(project, "Failed execution mvn %s", arguments.toString()); logger.warn(project, "🙈 Failed execution mvn %s", arguments.toString());
throw new IllegalStateException("Failed execution mvn " + arguments.toString(), result.getExecutionException()); throw new IllegalStateException("🙈 Failed execution mvn " + arguments.toString(),
result.getExecutionException());
} }
logger.log(project, "Successful execution mvn %s", arguments.toString()); logger.log(project, "🆗 Successful execution mvn %s", arguments.toString());
} catch (Exception e) { } catch (Exception e) {
if (e instanceof RuntimeException) { if (e instanceof RuntimeException) {
throw (RuntimeException) e; throw (RuntimeException) e;

View File

@@ -23,14 +23,16 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collector; import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.Tracker; import org.springframework.data.release.model.Tracker;
import org.springframework.data.release.model.TrainIteration; import org.springframework.data.release.model.TrainIteration;
import org.springframework.data.release.utils.ListWrapperCollector; import org.springframework.data.release.utils.ListWrapperCollector;
import org.springframework.data.util.Streamable; import org.springframework.data.util.Streamable;
import org.springframework.util.StringUtils;
/** /**
* Value object to represent a list of {@link Ticket}s. * Value object to represent a list of {@link Ticket}s.
@@ -100,8 +102,8 @@ public class Tickets implements Streamable<Ticket> {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(String.format("Train only tickets: %s of %s", tickets.size(), overallTotal)); builder.append(String.format("Train only tickets: %s of %s", tickets.size(), overallTotal));
builder.append("\n"); builder.append(IOUtils.LINE_SEPARATOR);
builder.append(StringUtils.collectionToDelimitedString(tickets, "\n")); builder.append(tickets.stream().map(it -> "\t" + it).collect(Collectors.joining(IOUtils.LINE_SEPARATOR)));
return builder.toString(); return builder.toString();
} }

View File

@@ -29,7 +29,7 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Logger { public class Logger {
private static final String PREFIX_TEMPLATE = "%s > %s"; private static final String PREFIX_TEMPLATE = "%-14s > %s";
private final java.util.logging.Logger LOGGER = HandlerUtils.getLogger(getClass()); private final java.util.logging.Logger LOGGER = HandlerUtils.getLogger(getClass());