Skip to content

Instantly share code, notes, and snippets.

@kimmowikman
Last active December 16, 2021 07:28
Show Gist options
  • Save kimmowikman/388a77953b7b7071956a9400a8766480 to your computer and use it in GitHub Desktop.
Save kimmowikman/388a77953b7b7071956a9400a8766480 to your computer and use it in GitHub Desktop.
package fi.luotocompany.logger;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* Simple and secure logger by Kimmo Wikman, Luoto Company
*/
public class SimpleLogger {
public enum LogLevel {DEBUG, INFO, WARN, ERROR}
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
private final LogLevel level;
private final String sourceName;
public SimpleLogger(final LogLevel level, final Class source) {
this.level = level;
this.sourceName = source.getName();
}
public void log(final LogLevel logLevel, final String message) {
if (this.level.ordinal() <= logLevel.ordinal()) {
final StringBuilder sb = new StringBuilder();
sb.append(LocalDateTime.now().format(DATE_FORMAT))
.append(" [")
.append(logLevel.toString())
.append("] ")
.append(sourceName)
.append(" - ")
.append(message);
System.out.println(sb.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment