1 16 17 20 package org.apache.log4j; 21 import java.io.IOException ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectOutputStream ; 24 import java.io.ObjectStreamException ; 25 import java.io.Serializable ; 26 27 39 public class Level extends Priority implements Serializable { 40 41 45 public static final int TRACE_INT = 5000; 46 47 50 final static public Level OFF = new Level(OFF_INT, "OFF", 0); 51 52 56 final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0); 57 58 61 final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3); 62 63 66 final static public Level WARN = new Level(WARN_INT, "WARN", 4); 67 68 72 final static public Level INFO = new Level(INFO_INT, "INFO", 6); 73 74 78 final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7); 79 80 85 public static final Level TRACE = new Level(TRACE_INT, "TRACE", 7); 86 87 88 91 final static public Level ALL = new Level(ALL_INT, "ALL", 7); 92 93 96 static final long serialVersionUID = 3491141966387921974L; 97 98 101 protected 102 Level(int level, String levelStr, int syslogEquivalent) { 103 super(level, levelStr, syslogEquivalent); 104 } 105 106 107 111 public 112 static 113 Level toLevel(String sArg) { 114 return (Level) toLevel(sArg, Level.DEBUG); 115 } 116 117 122 public 123 static 124 Level toLevel(int val) { 125 return (Level) toLevel(val, Level.DEBUG); 126 } 127 128 132 public 133 static 134 Level toLevel(int val, Level defaultLevel) { 135 switch(val) { 136 case ALL_INT: return ALL; 137 case DEBUG_INT: return Level.DEBUG; 138 case INFO_INT: return Level.INFO; 139 case WARN_INT: return Level.WARN; 140 case ERROR_INT: return Level.ERROR; 141 case FATAL_INT: return Level.FATAL; 142 case OFF_INT: return OFF; 143 case TRACE_INT: return Level.TRACE; 144 default: return defaultLevel; 145 } 146 } 147 148 153 public 154 static 155 Level toLevel(String sArg, Level defaultLevel) { 156 if(sArg == null) 157 return defaultLevel; 158 159 String s = sArg.toUpperCase(); 160 161 if(s.equals("ALL")) return Level.ALL; 162 if(s.equals("DEBUG")) return Level.DEBUG; 163 if(s.equals("INFO")) return Level.INFO; 164 if(s.equals("WARN")) return Level.WARN; 165 if(s.equals("ERROR")) return Level.ERROR; 166 if(s.equals("FATAL")) return Level.FATAL; 167 if(s.equals("OFF")) return Level.OFF; 168 if(s.equals("TRACE")) return Level.TRACE; 169 return defaultLevel; 170 } 171 172 178 private void readObject(final ObjectInputStream s) throws IOException , ClassNotFoundException { 179 s.defaultReadObject(); 180 level = s.readInt(); 181 syslogEquivalent = s.readInt(); 182 levelStr = s.readUTF(); 183 if (levelStr == null) { 184 levelStr = ""; 185 } 186 } 187 188 193 private void writeObject(final ObjectOutputStream s) throws IOException { 194 s.defaultWriteObject(); 195 s.writeInt(level); 196 s.writeInt(syslogEquivalent); 197 s.writeUTF(levelStr); 198 } 199 200 206 private Object readResolve() throws ObjectStreamException { 207 if (getClass() == Level.class) { 211 return toLevel(level); 212 } 213 return this; 217 } 218 } | Popular Tags |