Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change log format of aadarchi-maven-plugin #340

Closed
Riduidel opened this issue Mar 28, 2023 · 8 comments
Closed

Change log format of aadarchi-maven-plugin #340

Riduidel opened this issue Mar 28, 2023 · 8 comments
Assignees

Comments

@Riduidel
Copy link
Owner

Riduidel commented Mar 28, 2023

We currently output logs in the form

[�[1;34mINFO�[m] (org.ndx.aadarchi.base.ArchitectureEnhancer) Running enhancement org.ndx.aadarchi.base.enhancers.scm.SCMProjectCheckouter took 00:00:00.021

Can you

  1. Replace the parenthesis around class name by square brackets
  2. Limit the number of characters of this class name to 20
  3. Compress package names to only have first character

This would lead to log being in the form

[�[1;34mINFO�[m] <o.n.a.base.ArchitectureEnhancer> Running enhancement org.ndx.aadarchi.base.enhancers.scm.SCMProjectCheckouter took 00:00:00.021

@Riduidel
Copy link
Owner Author

I suggest you take a look at class MavenLoggingRedirectorHandler

@Helielzel
Copy link
Collaborator

Helielzel commented Mar 28, 2023

@Helielzel
Copy link
Collaborator

Helielzel commented Mar 29, 2023

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();
    }`

@Helielzel
Copy link
Collaborator

Helielzel commented Mar 29, 2023

`    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();
    }`

@Riduidel
Copy link
Owner Author

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 ...

@Helielzel
Copy link
Collaborator

    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();
    }

@Helielzel
Copy link
Collaborator

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);
    }

@Helielzel
Copy link
Collaborator

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants