Skip to content

Issue #4572 Implemented TAG_PAD#4994

Closed
gregw wants to merge 1 commit intojetty-10.0.xfrom
jetty-10.0.x-4572-TAG_PAD
Closed

Issue #4572 Implemented TAG_PAD#4994
gregw wants to merge 1 commit intojetty-10.0.xfrom
jetty-10.0.x-4572-TAG_PAD

Conversation

@gregw
Copy link
Copy Markdown
Contributor

@gregw gregw commented Jun 24, 2020

Implemented the TAG_PAD configuration for jetty log appender.

There was a half implementation for thread name padding, but that is not sufficient to align the log output. Tag padding works on the combined thread and logger name.

Implemented the TAG_PAD configuration
@gregw gregw requested a review from joakime June 24, 2020 12:54
Copy link
Copy Markdown
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite right.
Naming of this configuration is the big one for me.
The implementation could be simpler too.
And there's no need for @deprecated here (we are still in alpha/beta phase)

*/
static final String NAME_CONDENSE_KEY = "org.eclipse.jetty.logging.appender.NAME_CONDENSE";
static final String THREAD_PADDING_KEY = "org.eclipse.jetty.logging.appender.THREAD_PADDING";
static final String TAG_PAD_KEY = "org.eclipse.jetty.logging.appender.TAG_PAD";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a better name.
TAG is meaningless and vague.
THREAD isn't what this is about either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were instead a name that indicated the tab stop of where the "message" portion of the log output should begin, then the logic below gets simpler.

Example

package text;

public class TabStopDemo
{
    public static void main(String[] args)
    {
        String padding = " ".repeat(20);
        System.out.printf("[%s]%n", padding);

        int tabStop = 10;
        tabStopTest(tabStop, "hello", "friend");
        tabStopTest(tabStop, "my name is", "inigo montoya");
        tabStopTest(tabStop, "you killed my father", "prepare to die");
    }

    private static void tabStopTest(int tabStop, String start, String message)
    {
        StringBuilder builder = new StringBuilder();
        builder.append(start);
        int padHere = tabStop - builder.length();
        if(padHere > 0)
            builder.append(" ".repeat(padHere));
        else
            builder.append(' ');
        builder.append(message);
        System.out.println(builder);
    }
}

StringBuilder b = new StringBuilder(padding);
while (b.length() < padding)
b.append(' ');
this.tagPadding = b.toString();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire else branch can be ...

this.tagPadding = " ".repeat(padding);

public void testStdErrLogDebug()
{
JettyLoggerConfiguration config = new JettyLoggerConfiguration();
Properties props = new Properties();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have preferred a new test method, not polluting the existing one.
This new mutated test method is testing too many things now.

@joakime
Copy link
Copy Markdown
Contributor

joakime commented Jun 24, 2020

I created PR #4997 as an alternate approach for this.

@gregw
Copy link
Copy Markdown
Contributor Author

gregw commented Jun 25, 2020

Closed in favour of #4997

@gregw gregw closed this Jun 25, 2020
@joakime joakime deleted the jetty-10.0.x-4572-TAG_PAD branch August 14, 2020 14:28
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

Successfully merging this pull request may close these issues.

2 participants