Skip to content

Commit

Permalink
Missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
AZWN committed Jul 19, 2023
1 parent 0029665 commit 5510c05
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions nabl2.solver/src/main/java/mb/nabl2/log/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package mb.nabl2.log;

import org.metaborg.util.log.ILogger;
import org.metaborg.util.log.LoggerUtils;

public class Logger {

private static final ILogger log = LoggerUtils.logger(Logger.class);

private final String name;

public Logger(String name) {
this.name = truncate(name);
}

public void debug(String message, Object... args) {
log(format(message, args), "[DEBUG] -");
}

public void debug(String message, Throwable ex, Object... args) {
log(format(message, args), "[DEBUG] -");
ex.printStackTrace(System.out);
}

public void info(String message, Object... args) {
log(format(message, args), "[INFO] -");
}

public void info(String message, Throwable ex, Object... args) {
log(format(message, args), "[INFO] -");
ex.printStackTrace(System.out);
}

public void warn(String message, Object... args) {
log(format(message, args), "[WARN] -");
}

public void warn(String message, Throwable ex, Object... args) {
log(format(message, args), "[WARN] -");
ex.printStackTrace(System.out);
}

public void error(String message, Object... args) {
log(format(message, args), "[ERROR] -");
}

public void error(String message, Throwable ex, Object... args) {
log(format(message, args), "[ERROR] -");
ex.printStackTrace(System.out);
}

private String format(String format, Object... args) {
return log.format(format, args);
}

private void log(String message, String level) {
System.out.printf("%s %-32s | %s%n", level, name, message);
}

private String truncate(String name) {
if(name.length() > 32) {
return name.substring(name.length() - 32);
} else {
return name;
}
}

public static Logger logger(Class<?> clz) {
return new Logger(clz.getCanonicalName());
}

}

0 comments on commit 5510c05

Please sign in to comment.