Closed Riduidel closed 1 year ago
I suggest you take a look at class MavenLoggingRedirectorHandler
Compile with -X to display logs ? https://stackoverflow.com/questions/4782089/how-to-change-maven-logging-level-to-display-only-warning-and-errors
Shortens the source in the logs
` public static String shortenSource(String originalSource) {
String[] parts = originalSource.split("\\.");
StringBuilder newSource = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
if (i > 0) {
newSource.append(".");
}
newSource.append(parts[i].charAt(0));
}
return newSource.toString();
}`
` public static String shortenSource(String originalSource) {
String[] parts = originalSource.split("\\.");
StringBuilder newSource = new StringBuilder();
System.out.println(parts.length);
for (int i = 0; i < parts.length - 1; i++) {
if (i > 0) {
newSource.append(".");
}
newSource.append(parts[i].charAt(0));
}
newSource.append("." + parts[parts.length - 1]);
return newSource.toString();
}`
More clearly, if full class name (including packages) is smaller than 20 characters, show everything. If full class name is longer than 20 characters, start by replacing package names by their first letter, starting by the first one. Never compress class name.
Here are some example
org.ndx.aadarchi.gitlab.GitlabSCMHandler
should be abbreviated to o.n.a.g.GitlabSCMHandler
(24 characters)org.ndx.aadarchi.base.enhancers.ToDsl
should be abbreviated to o.n.a.b.e.ToDsl
(16 characters)I think you could write that in a unit test ...
public static Integer getTotalSize(String[] parts) {
int totalSize = 0;
for (int i = 0; i < parts.length - 1; i++) {
totalSize += parts[i].length() + 1;
}
return totalSize;
}
public static String shortenSource(String originalSource) {
if (originalSource.length() <= 20) {
return originalSource;
}
String[] parts = originalSource.split("\\.");
StringBuilder newSourceBuilder = new StringBuilder();
int classLength = parts[parts.length - 1].length();
/*
if (classLength >= 20) {
for (int i = 0; i < parts.length - 1; i++) {
newSourceBuilder.append(parts[i].charAt(0) + ".");
}
return newSourceBuilder.append(parts[parts.length - 1]).toString();
}*/
for (int i = 0; i < parts.length - 1; i++) {
if (getTotalSize(parts) + classLength > 20) {
//parts[i] = parts[i].replace(parts[i], String.valueOf(parts[i].charAt(0)));
parts[i] = String.valueOf(parts[i].charAt(0));
}
newSourceBuilder.append(parts[i] + ".");
}
return newSourceBuilder.append(parts[parts.length - 1]).toString();
}
public static Integer getTotalSize(String[] parts) {
int totalSize = 0;
for (int i = 0; i < parts.length - 1; i++) {
totalSize += parts[i].length() + 1;
}
return totalSize;
}
public static String shortenSource(String originalSource) {
String[] parts = originalSource.split("\\.");
int classLength = parts[parts.length - 1].length();
for (int i = 0; i < parts.length - 1; i++) {
if (getTotalSize(parts) + classLength > 20) {
parts[i] = String.valueOf(parts[i].charAt(0));
}
}
return String.join(".", parts);
}
public static Integer getTotalSize(String[] parts) {
return Arrays.stream(parts)
.limit(parts.length - 1)
.mapToInt(String::length)
.sum() + parts.length - 1;
}
public static String shortenSource(String originalSource) {
String[] parts = originalSource.split("\\.");
int classLength = parts[parts.length - 1].length();
if (getTotalSize(parts) + classLength > 20) {
parts = Arrays.stream(parts)
.limit(parts.length - 1)
.map(s -> s.substring(0, 1))
.toArray(String[]::new);
}
return String.join(".", parts);
}
We currently output logs in the form
Can you
This would lead to log being in the form