Initial commit
This commit is contained in:
87
src/main/java/net/locusworks/logger/LogLevel.java
Normal file
87
src/main/java/net/locusworks/logger/LogLevel.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package net.locusworks.logger;
|
||||
|
||||
/**
|
||||
* Enumeration specifying th severity level of the logged message
|
||||
* @author Isaac Parenteau
|
||||
* @version 1.0.0
|
||||
* @date 02/15/2018
|
||||
*/
|
||||
public enum LogLevel {
|
||||
OFF(7, "OFF"),
|
||||
FATAL(6, "FATAL"),
|
||||
ERROR(5, "ERROR"),
|
||||
WARN(4, "WARN"),
|
||||
INFO(3, "INFO"),
|
||||
DEBUG(2, "DEBUG"),
|
||||
TRACE(1, "TRACE"),
|
||||
ALL(0, "ALL");
|
||||
|
||||
private Integer intLevel;
|
||||
private String levelName;
|
||||
|
||||
private LogLevel(Integer intLevel, String levelName) {
|
||||
this.intLevel = intLevel;
|
||||
this.levelName = levelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.toName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the log level
|
||||
* @return levelName
|
||||
*/
|
||||
public String toName() {
|
||||
return this.levelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the integer representation of the log level
|
||||
* @return intLevel
|
||||
*/
|
||||
public Integer toInt() {
|
||||
return this.intLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this log can log compared to the other log
|
||||
* @param otherLevel the other level to check
|
||||
* @return true if the current level is higher than the other level, false otherwise
|
||||
*/
|
||||
public boolean log(LogLevel otherLevel) {
|
||||
if (otherLevel == null) {
|
||||
return false;
|
||||
}
|
||||
return this.toInt() >= otherLevel.toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log level based off of an integer value
|
||||
* @param level The log level integer value
|
||||
* @return logLevel based on the integer value or null if not found
|
||||
*/
|
||||
public static LogLevel getEnum(Integer level) {
|
||||
for (LogLevel l : values()) {
|
||||
if (l.toInt().equals(level)) {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log level based off the level name
|
||||
* @param levelName level name to get
|
||||
* @return the log level for the name or null if it cant be found
|
||||
*/
|
||||
public static LogLevel getEnum(String levelName) {
|
||||
for (LogLevel l : values()) {
|
||||
if (l.toName().equalsIgnoreCase(levelName)) {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user