Skip to content

Commit

Permalink
Added Log#format
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Apr 3, 2024
1 parent 8de9993 commit d659d0a
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/main/java/dev/latvian/apps/webutils/ansi/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ public enum Type {
public static Log INSTANCE = new Log();

public static void info(Object message) {
INSTANCE.log(Type.INFO, Ansi.of(message));
INSTANCE.log(Type.INFO, message);
}

public static void warn(Object message) {
INSTANCE.log(Type.WARN, Ansi.of(message).yellow());
INSTANCE.log(Type.WARN, message);
}

public static void error(Object message) {
INSTANCE.log(Type.ERROR, Ansi.of(message).error());
INSTANCE.log(Type.ERROR, message);
}

public static void debug(Object message) {
INSTANCE.log(Type.DEBUG, Ansi.of(message).lightGray());
INSTANCE.log(Type.DEBUG, message);
}

public static void success(Object message) {
INSTANCE.log(Type.SUCCESS, Ansi.of(message).green());
INSTANCE.log(Type.SUCCESS, message);
}

public static void fail(Object message) {
INSTANCE.log(Type.FAIL, Ansi.of(message).red());
INSTANCE.log(Type.FAIL, message);
}

public static void success(Object message, boolean success) {
Expand All @@ -51,19 +51,32 @@ public static void success(Object message, boolean success) {
}

public static void important(Object message) {
INSTANCE.log(Type.IMPORTANT, Ansi.of(message).orange());
INSTANCE.log(Type.IMPORTANT, message);
}

public static void code(Object message) {
INSTANCE.log(Type.CODE, Ansi.of(message).teal());
INSTANCE.log(Type.CODE, message);
}

public void log(Type type, AnsiComponent message) {
public void log(Type type, Object message) {
var now = new Date();
var c = Ansi.of();
c.append(Ansi.cyan(TimeUtils.formatDate(new StringBuilder(), now).toString()));
c.append(' ');
c.append(message);
c.append(format(Ansi.of(message), type));
System.out.println(c);
}

public AnsiComponent format(Object message, Type type) {
return switch (type) {
case WARN -> Ansi.of(message).yellow();
case ERROR -> Ansi.of(message).error();
case DEBUG -> Ansi.of(message).lightGray();
case SUCCESS -> Ansi.of(message).green();
case FAIL -> Ansi.of(message).red();
case IMPORTANT -> Ansi.of(message).orange();
case CODE -> Ansi.of(message).teal();
default -> Ansi.of(message);
};
}
}

0 comments on commit d659d0a

Please sign in to comment.