1 20 21 22 package org.snmp4j.log; 23 24 public class LogLevel { 25 26 public static final int LEVEL_NONE = 0; 27 public static final int LEVEL_OFF = 1; 28 public static final int LEVEL_ALL = 2; 29 public static final int LEVEL_TRACE = 3; 30 public static final int LEVEL_DEBUG = 4; 31 public static final int LEVEL_INFO = 5; 32 public static final int LEVEL_WARN = 6; 33 public static final int LEVEL_ERROR = 7; 34 public static final int LEVEL_FATAL = 8; 35 36 private static final String [] LEVEL_STRINGS = { 37 "NONE","OFF","ALL","TRACE","DEBUG","INFO","WARN","INFO","ERROR","FATAL" 38 }; 39 40 public static final LogLevel NONE = new LogLevel(LEVEL_NONE); 41 public static final LogLevel OFF = new LogLevel(LEVEL_OFF); 42 public static final LogLevel ALL = new LogLevel(LEVEL_ALL); 43 public static final LogLevel TRACE = new LogLevel(LEVEL_TRACE); 44 public static final LogLevel DEBUG = new LogLevel(LEVEL_DEBUG); 45 public static final LogLevel INFO = new LogLevel(LEVEL_INFO); 46 public static final LogLevel WARN = new LogLevel(LEVEL_WARN); 47 public static final LogLevel ERROR = new LogLevel(LEVEL_ERROR); 48 public static final LogLevel FATAL = new LogLevel(LEVEL_FATAL); 49 50 private int level; 51 52 public LogLevel(int level) { 53 if ((level < 0) || (level > 8)) { 54 throw new IllegalArgumentException ("Unknown log level "+level); 55 } 56 this.level = level; 57 } 58 59 public LogLevel(String levelString) { 60 this(levelFromString(levelString)); 61 } 62 63 72 public static int levelFromString(String levelString) { 73 int ind = -1; 74 for (int i=0; i<LEVEL_STRINGS.length; i++) { 75 if (LEVEL_STRINGS[i].equals(levelString)) { 76 ind = i; 77 break; 78 } 79 } 80 return ind; 81 } 82 83 92 public static LogLevel toLevel(String levelString) { 93 return new LogLevel(levelFromString(levelString)); 94 } 95 96 public int getLevel() { 97 return level; 98 } 99 100 public String toString() { 101 return LEVEL_STRINGS[level]; 102 } 103 104 } 105 | Popular Tags |