1
0
mirror of https://github.com/suk-ws/messiva.git synced 2024-11-22 17:04:51 +08:00

add separator for message in SimpleFormatter, well-define null-define annotation.

This commit is contained in:
A.C.Sukazyo Eyre 2023-10-15 18:21:50 +08:00
parent f4697a45c0
commit db47d6f819
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
6 changed files with 53 additions and 37 deletions

View File

@ -14,6 +14,7 @@ public class SimpleFormatter implements ILogFormatter {
@Nonnull public String startLevelTag = "[";
@Nonnull public String endLevelTag = "]";
public char followingLineFillChar = '\'';
@Nonnull public String messageSeparator = " ";
@Nonnull
@Override
@ -22,10 +23,12 @@ public class SimpleFormatter implements ILogFormatter {
message.append(startTimestamp).append(log.timestamp).append(endTimestamp)
.append(startThreadName).append(log.thread.getName()).append(endThreadName);
final String promptNewline = StringUtils.repeatChar(followingLineFillChar, message.length());
message.append(startLevelTag).append(log.level.tag()).append(endLevelTag).append(log.message.message[0]);
message.append(startLevelTag).append(log.level.tag()).append(endLevelTag)
.append(messageSeparator).append(log.message.message[0]);
for (int i = 1; i < log.message.message.length; i++) {
message.append('\n').append(promptNewline)
.append(startLevelTag).append(log.level.tag()).append(endLevelTag).append(log.message.message[i]);
.append(startLevelTag).append(log.level.tag()).append(endLevelTag)
.append(messageSeparator).append(log.message.message[i]);
}
return message.toString();
}

View File

@ -1,6 +1,8 @@
package cc.sukazyo.messiva.log;
import javax.annotation.Nonnull;
public interface ILogLevel {
float level();
String tag();
@Nonnull String tag();
}

View File

@ -1,33 +1,35 @@
package cc.sukazyo.messiva.log;
import javax.annotation.Nonnull;
public interface ILogLevelImpl {
void trace (String message);
void trace (@Nonnull String message);
void debug (String message);
void debug (@Nonnull String message);
void info (String message);
void info (@Nonnull String message);
void warn (String message);
void warn (@Nonnull String message);
void warning (String message);
void warning (@Nonnull String message);
void error (String message);
void error (@Nonnull String message);
void fatal (String message);
void fatal (@Nonnull String message);
void trace (Message message);
void trace (@Nonnull Message message);
void debug (Message message);
void debug (@Nonnull Message message);
void info (Message message);
void info (@Nonnull Message message);
void warn (Message message);
void warn (@Nonnull Message message);
void warning (Message message);
void warning (@Nonnull Message message);
void error (Message message);
void error (@Nonnull Message message);
void fatal (Message message);
void fatal (@Nonnull Message message);
}

View File

@ -1,5 +1,7 @@
package cc.sukazyo.messiva.log;
import javax.annotation.Nonnull;
public enum LogLevels implements ILogLevel {
ALL (-Float.MAX_VALUE, "####"),
@ -12,9 +14,9 @@ public enum LogLevels implements ILogLevel {
NONE(Float.MAX_VALUE, "!!!!");
public final float level;
public final String tag;
@Nonnull public final String tag;
LogLevels (float level, String tag) {
LogLevels (float level, @Nonnull String tag) {
this.level = level;
this.tag = tag;
}
@ -22,6 +24,7 @@ public enum LogLevels implements ILogLevel {
@Override
public float level () { return this.level; }
@Nonnull
@Override
public String tag () { return this.tag; }

View File

@ -1,10 +1,14 @@
package cc.sukazyo.messiva.log;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class Message {
@Nonnull
public final String[] message;
public Message(String message) {
public Message(@Nullable String message) {
this.message = message == null ? new String[]{} : message.split("\n");
}

View File

@ -20,82 +20,84 @@ public class Logger implements ILogLevelImpl {
appends = new ArrayList<>();
}
public Logger (IAppender... appends) {
public Logger (@Nonnull IAppender... appends) {
this();
this.appends.addAll(Arrays.asList(appends));
}
@Nonnull
public Logger minLevel (@Nonnull ILogLevel minLevel) {
levelSetting.minLevel(minLevel);
return this;
}
@Nonnull
public Logger maxLevel (@Nonnull ILogLevel maxLevel) {
levelSetting.maxLevel(maxLevel);
return this;
}
public void trace (String message) {
public void trace (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.TRACE));
}
public void debug (String message) {
public void debug (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.DEBUG));
}
public void info (String message) {
public void info (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.INFO));
}
public void warn (String message) {
public void warn (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.WARN));
}
public void warning (String message) {
public void warning (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.WARN));
}
public void error (String message) {
public void error (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.ERROR));
}
public void fatal (String message) {
public void fatal (@Nonnull String message) {
pushToAllAppender(new Log(1, new Message(message), LogLevels.FATAL));
}
public void trace (Message message) {
public void trace (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.TRACE));
}
public void debug (Message message) {
public void debug (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.DEBUG));
}
public void info (Message message) {
public void info (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.INFO));
}
public void warn (Message message) {
public void warn (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.WARN));
}
public void warning (Message message) {
public void warning (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.WARN));
}
public void error (Message message) {
public void error (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.ERROR));
}
public void fatal (Message message) {
public void fatal (@Nonnull Message message) {
pushToAllAppender(new Log(1, message, LogLevels.FATAL));
}
public void log (String message, ILogLevel level) {
public void log (@Nonnull String message, @Nonnull ILogLevel level) {
pushToAllAppender(new Log(1, new Message(message), level));
}
public void log (Message message, ILogLevel level) {
public void log (@Nonnull Message message, @Nonnull ILogLevel level) {
pushToAllAppender(new Log(1, message, level));
}