diff --git a/src/main/java/cc/sukazyo/messiva/formatter/SimpleFormatter.java b/src/main/java/cc/sukazyo/messiva/formatter/SimpleFormatter.java index 60d7ee2..43c7c7b 100644 --- a/src/main/java/cc/sukazyo/messiva/formatter/SimpleFormatter.java +++ b/src/main/java/cc/sukazyo/messiva/formatter/SimpleFormatter.java @@ -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(); } diff --git a/src/main/java/cc/sukazyo/messiva/log/ILogLevel.java b/src/main/java/cc/sukazyo/messiva/log/ILogLevel.java index 6f3caa5..cd0c571 100644 --- a/src/main/java/cc/sukazyo/messiva/log/ILogLevel.java +++ b/src/main/java/cc/sukazyo/messiva/log/ILogLevel.java @@ -1,6 +1,8 @@ package cc.sukazyo.messiva.log; +import javax.annotation.Nonnull; + public interface ILogLevel { float level(); - String tag(); + @Nonnull String tag(); } diff --git a/src/main/java/cc/sukazyo/messiva/log/ILogLevelImpl.java b/src/main/java/cc/sukazyo/messiva/log/ILogLevelImpl.java index b2d657c..b07f5e4 100644 --- a/src/main/java/cc/sukazyo/messiva/log/ILogLevelImpl.java +++ b/src/main/java/cc/sukazyo/messiva/log/ILogLevelImpl.java @@ -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); } diff --git a/src/main/java/cc/sukazyo/messiva/log/LogLevels.java b/src/main/java/cc/sukazyo/messiva/log/LogLevels.java index 8d3284d..3096722 100644 --- a/src/main/java/cc/sukazyo/messiva/log/LogLevels.java +++ b/src/main/java/cc/sukazyo/messiva/log/LogLevels.java @@ -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; } diff --git a/src/main/java/cc/sukazyo/messiva/log/Message.java b/src/main/java/cc/sukazyo/messiva/log/Message.java index c51b725..50dd88b 100644 --- a/src/main/java/cc/sukazyo/messiva/log/Message.java +++ b/src/main/java/cc/sukazyo/messiva/log/Message.java @@ -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"); } diff --git a/src/main/java/cc/sukazyo/messiva/logger/Logger.java b/src/main/java/cc/sukazyo/messiva/logger/Logger.java index 194b3d9..a613106 100644 --- a/src/main/java/cc/sukazyo/messiva/logger/Logger.java +++ b/src/main/java/cc/sukazyo/messiva/logger/Logger.java @@ -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)); }