001package org.slf4j.event; 002 003import static org.slf4j.event.EventConstants.DEBUG_INT; 004import static org.slf4j.event.EventConstants.ERROR_INT; 005import static org.slf4j.event.EventConstants.INFO_INT; 006import static org.slf4j.event.EventConstants.TRACE_INT; 007import static org.slf4j.event.EventConstants.WARN_INT; 008 009/** 010 * SLF4J's internal representation of a level. 011 * 012 * @author Ceki Gülcü 013 * @since 1.7.15 014 */ 015public enum Level { 016 017 ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), TRACE(TRACE_INT, "TRACE"); 018 019 private final int levelInt; 020 private final String levelStr; 021 022 Level(int i, String s) { 023 levelInt = i; 024 levelStr = s; 025 } 026 027 public int toInt() { 028 return levelInt; 029 } 030 031 public static Level intToLevel(int levelInt) { 032 switch (levelInt) { 033 case (TRACE_INT): 034 return TRACE; 035 case (DEBUG_INT): 036 return DEBUG; 037 case (INFO_INT): 038 return INFO; 039 case (WARN_INT): 040 return WARN; 041 case (ERROR_INT): 042 return ERROR; 043 default: 044 throw new IllegalArgumentException("Level integer [" + levelInt + "] not recognized."); 045 } 046 } 047 048 /** 049 * Returns the string representation of this Level. 050 */ 051 public String toString() { 052 return levelStr; 053 } 054 055}