PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/apache-log4j-1.2.17/examples/customLevel/XLevel.java

#
Java | 90 lines | 44 code | 21 blank | 25 comment | 5 complexity | aac76072fcf53af1403564b296a58470 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package examples.customLevel;
  18. import org.apache.log4j.Level;
  19. /**
  20. This class introduces a new level level called TRACE. TRACE has
  21. lower level than DEBUG.
  22. */
  23. public class XLevel extends Level {
  24. private static final long serialVersionUID = 2626753561969426769L;
  25. static public final int TRACE_INT = Level.DEBUG_INT - 1;
  26. static public final int LETHAL_INT = Level.FATAL_INT + 1;
  27. private static String TRACE_STR = "TRACE";
  28. private static String LETHAL_STR = "LETHAL";
  29. public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_STR, 7);
  30. public static final XLevel LETHAL = new XLevel(LETHAL_INT, LETHAL_STR,
  31. 0);
  32. protected
  33. XLevel(int level, String strLevel, int syslogEquiv) {
  34. super(level, strLevel, syslogEquiv);
  35. }
  36. /**
  37. Convert the string passed as argument to a level. If the
  38. conversion fails, then this method returns {@link #TRACE}.
  39. */
  40. public
  41. static
  42. Level toLevel(String sArg) {
  43. return (Level) toLevel(sArg, XLevel.TRACE);
  44. }
  45. public
  46. static
  47. Level toLevel(String sArg, Level defaultValue) {
  48. if(sArg == null) {
  49. return defaultValue;
  50. }
  51. String stringVal = sArg.toUpperCase();
  52. if(stringVal.equals(TRACE_STR)) {
  53. return XLevel.TRACE;
  54. } else if(stringVal.equals(LETHAL_STR)) {
  55. return XLevel.LETHAL;
  56. }
  57. return Level.toLevel(sArg, (Level) defaultValue);
  58. }
  59. public
  60. static
  61. Level toLevel(int i) throws IllegalArgumentException {
  62. switch(i) {
  63. case TRACE_INT: return XLevel.TRACE;
  64. case LETHAL_INT: return XLevel.LETHAL;
  65. }
  66. return Level.toLevel(i);
  67. }
  68. }