[MNG-7822] Add support for TRACE logging level (with style "bold,magenta") (#1215)

Signed-off-by: crazyhzm <crazyhzm@apache.org>
This commit is contained in:
huazhongming 2023-08-25 23:51:43 +08:00 committed by GitHub
parent f2593b97ef
commit 7d66d19f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 1 deletions

View File

@ -27,9 +27,21 @@ import org.apache.maven.api.annotations.Nonnull;
* @see MessageBuilderFactory
*/
public interface MessageBuilder {
/**
* Append message content in trace style.
* By default, bold magenta
*
* @param message the message to append
* @return the current builder
*/
@Nonnull
MessageBuilder trace(Object message);
/**
* Append message content in debug style.
* By default, bold cyan
*
* @param message the message to append
* @return the current builder
*/
@ -39,6 +51,7 @@ public interface MessageBuilder {
/**
* Append message content in info style.
* By default, bold blue
*
* @param message the message to append
* @return the current builder
*/
@ -48,6 +61,7 @@ public interface MessageBuilder {
/**
* Append message content in warning style.
* By default, bold yellow
*
* @param message the message to append
* @return the current builder
*/
@ -57,6 +71,7 @@ public interface MessageBuilder {
/**
* Append message content in error style.
* By default, bold red
*
* @param message the message to append
* @return the current builder
*/
@ -66,6 +81,7 @@ public interface MessageBuilder {
/**
* Append message content in success style.
* By default, bold green
*
* @param message the message to append
* @return the current builder
*/
@ -75,6 +91,7 @@ public interface MessageBuilder {
/**
* Append message content in failure style.
* By default, bold red
*
* @param message the message to append
* @return the current builder
*/
@ -84,6 +101,7 @@ public interface MessageBuilder {
/**
* Append message content in strong style.
* By default, bold
*
* @param message the message to append
* @return the current builder
*/
@ -93,6 +111,7 @@ public interface MessageBuilder {
/**
* Append message content in mojo style.
* By default, green
*
* @param message the message to append
* @return the current builder
*/
@ -102,6 +121,7 @@ public interface MessageBuilder {
/**
* Append message content in project style.
* By default, cyan
*
* @param message the message to append
* @return the current builder
*/
@ -113,6 +133,7 @@ public interface MessageBuilder {
//
/**
* Append content to the message buffer.
*
* @param value the content to append
* @param offset the index of the first {@code char} to append
* @param len the number of {@code char}s to append
@ -123,6 +144,7 @@ public interface MessageBuilder {
/**
* Append content to the message buffer.
*
* @param value the content to append
* @return the current builder
*/
@ -131,6 +153,7 @@ public interface MessageBuilder {
/**
* Append content to the message buffer.
*
* @param value the content to append
* @param start the starting index of the subsequence to be appended
* @param end the end index of the subsequence to be appended
@ -141,6 +164,7 @@ public interface MessageBuilder {
/**
* Append content to the message buffer.
*
* @param value the content to append
* @return the current builder
*/
@ -149,6 +173,7 @@ public interface MessageBuilder {
/**
* Append content to the message buffer.
*
* @param value the content to append
* @return the current builder
*/
@ -157,6 +182,7 @@ public interface MessageBuilder {
/**
* Append newline to the message buffer.
*
* @return the current builder
*/
@Nonnull
@ -165,6 +191,7 @@ public interface MessageBuilder {
/**
* Append formatted content to the buffer.
* @see String#format(String, Object...)
*
* @param pattern a <a href="../util/Formatter.html#syntax">format string</a>
* @param args arguments referenced by the format specifiers in the format string
* @return the current builder
@ -174,6 +201,7 @@ public interface MessageBuilder {
/**
* Return the built message.
*
* @return the message
*/
@Nonnull

View File

@ -35,6 +35,12 @@ public class DefaultMessageBuilder implements MessageBuilder {
this.buffer = buffer;
}
@Override
@Nonnull
public MessageBuilder trace(Object o) {
return a(o);
}
@Override
@Nonnull
public MessageBuilder debug(Object o) {

View File

@ -594,6 +594,7 @@ public class MavenCli {
if (MessageUtils.isColorEnabled()) {
MessageBuilder buff = MessageUtils.builder();
buff.a("Message styles: ");
buff.trace("trace").a(' ');
buff.debug("debug").a(' ');
buff.info("info").a(' ');
buff.warning("warning").a(' ');

View File

@ -35,6 +35,12 @@ public class JansiMessageBuilder implements MessageBuilder {
this.ansi = Ansi.ansi(sb);
}
@Override
@Nonnull
public MessageBuilder trace(Object o) {
return style(Style.TRACE, o);
}
@Override
@Nonnull
public MessageBuilder debug(Object o) {

View File

@ -28,6 +28,7 @@ import org.fusesource.jansi.Ansi.Color;
* @since 4.0.0
*/
enum Style {
TRACE("bold,magenta"),
DEBUG("bold,cyan"),
INFO("bold,blue"),
WARNING("bold,yellow"),

View File

@ -38,7 +38,7 @@ public class MavenSimpleLogger extends SimpleLogger {
protected String renderLevel(int level) {
switch (level) {
case LOG_LEVEL_TRACE:
return builder().debug("TRACE").build();
return builder().trace("TRACE").build();
case LOG_LEVEL_DEBUG:
return builder().debug("DEBUG").build();
case LOG_LEVEL_INFO: