Skip to content

Commit

Permalink
Added compatibility with java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
Voinea-Radu committed Sep 24, 2024
1 parent 954f5a4 commit b0f1db0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dependencies {

tasks {
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

test {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com.voinearadu/logger/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ private static void log(Level level, Object object, @NotNull ConsoleColor color,
id = caller.getSimpleName() + ".java";
}

String log = switch (object) {
case null -> "null";
case Throwable throwable -> StackTraceUtils.toString(throwable);
case StackTraceElement[] stackTraceElements -> StackTraceUtils.toString(stackTraceElements);
default -> object.toString();
};
String log = null;

if (object == null) {
log = "null";
} else if (object instanceof Throwable) {
log = StackTraceUtils.toString((Throwable) object);
} else if (object instanceof StackTraceElement[]) {
log = StackTraceUtils.toString((StackTraceElement[]) object);
} else {
log = object.toString();
}

org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(id);
logger.info(color + log + ConsoleColor.RESET);
Expand Down

0 comments on commit b0f1db0

Please sign in to comment.