sjava-logging library는 level에 따른 로깅 가능여부를 체크하고 있지는 않습니다.
아래의 Level은 로깅파일의 분류 및 파일의 내용에 기입을 하기 위한 클래스입니다.
그리고, Level에 대한 사용을 위해서는 LevelFactory를 사용하면 됩니다.
LevelFactory.java
import java.util.Map;
import java.util.HashMap;
/**
*
* @author mcsong@gmail.com
* @since 2009. 7. 1.
*/
public class LevelFactory {
/** map of levels */
private Map<String, Level> levelMap;
/** singleton instance */
private static LevelFactory instance = new LevelFactory();
/** constructor */
private LevelFactory() {
this.levelMap = new HashMap<String, Level>();
this.levelMap.put(“all”, new Level(0, “all”));
this.levelMap.put(“fatal”, new Level(1, “fatal”));
this.levelMap.put(“error”, new Level(2, “error”));
this.levelMap.put(“warn”, new Level(3, “warn”));
this.levelMap.put(“info”, new Level(4, “info”));
this.levelMap.put(“debug”, new Level(5, “debug”));
this.levelMap.put(“trace”, new Level(6, “trace”));
this.levelMap.put(“system”, new Level(7, “system”));
}
/**
*
* @return
*/
public static LevelFactory getInstance() {
return instance;
}
/**
*
* @param level
* @return
*/
public Level getLevel(int level) {
switch (level) {
case 1:
return this.getLevel(“fatal”);
case 2:
return this.getLevel(“error”);
case 3:
return this.getLevel(“warn”);
case 4:
return this.getLevel(“info”);
case 5:
return this.getLevel(“debug”);
case 6:
return this.getLevel(“trace”);
case 7:
return this.getLevel(“system”);
default:
return this.getLevel(“all”);
}
}
/**
*
* @param name
* @return
*/
public Level getLevel(String name) {
if (name == null)
return null;
if(!this.levelMap.containsKey(name.toLowerCase()))
return (Level)this.levelMap.get(“all”);
return (Level)this.levelMap.get(name.toLowerCase());
}
}
Level.java
/**
*
* @author mcsong@gmail.com
* @since 2009. 6. 19.
*/
public class Level {
/** level number */
public int level;
/** level name */
public String name;
/**
* Constructor
*
* @param level
* @param name
*/
public Level(int level, String name) {
this.level = level;
this.name = name;
}
/**
* @return the level
*/
public int getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(int level) {
this.level = level;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return “name is ” + this.name + “, level is ” + this.level;
}
}