private Level(final String name, final int intLevel) { if (Strings.isEmpty(name)) { throw new IllegalArgumentException("Illegal null or empty Level name."); } if (intLevel < 0) { throw new IllegalArgumentException("Illegal Level int less than zero."); } this.name = name; this.intLevel = intLevel; this.standardLevel = StandardLevel.getStandardLevel(intLevel); if (LEVELS.putIfAbsent(name, this) != null) { throw new IllegalStateException("Level " + name + " has already been defined."); } }
/** * Method to convert custom Levels into a StandardLevel for conversion to other systems. * * @param intLevel The integer value of the Level. * @return The StandardLevel. */ public static StandardLevel getStandardLevel(final int intLevel) { StandardLevel level = StandardLevel.OFF; for (final StandardLevel lvl : LEVELSET) { if (lvl.intLevel() > intLevel) { break; } level = lvl; } return level; } }
/** Create a new instance based on a standard log4j level. */ LevelTag(StandardLevel std) { this.std = std; this.value = String.format("%d_%s", ordinal(), std.name()); }
/** Get the tag corresponding to the log4j level. */ static LevelTag get(Level level) { final StandardLevel stdLevel = level.getStandardLevel(); return LEVELS[stdLevel.ordinal()]; } }
private Level(final String name, final int intLevel) { if (Strings.isEmpty(name)) { throw new IllegalArgumentException("Illegal null or empty Level name."); } if (intLevel < 0) { throw new IllegalArgumentException("Illegal Level int less than zero."); } this.name = name; this.intLevel = intLevel; this.standardLevel = StandardLevel.getStandardLevel(intLevel); if (LEVELS.putIfAbsent(name, this) != null) { throw new IllegalStateException("Level " + name + " has already been defined."); } }
/** * Method to convert custom Levels into a StandardLevel for conversion to other systems. * * @param intLevel The integer value of the Level. * @return The StandardLevel. */ public static StandardLevel getStandardLevel(final int intLevel) { StandardLevel level = StandardLevel.OFF; for (final StandardLevel lvl : LEVELSET) { if (lvl.intLevel() > intLevel) { break; } level = lvl; } return level; } }
@Override public SeverityLevel getNormalizedSeverityLevel() { int log4jLevelAsInt = logEvent.getLevel().intLevel(); switch (StandardLevel.getStandardLevel(log4jLevelAsInt)) { case FATAL: return SeverityLevel.Critical; case ERROR: return SeverityLevel.Error; case WARN: return SeverityLevel.Warning; case INFO: return SeverityLevel.Information; case TRACE: case DEBUG: case ALL: return SeverityLevel.Verbose; default: InternalLogger.INSTANCE.error("Unknown Log4j v2 option, %d, using TRACE level as default", log4jLevelAsInt); return SeverityLevel.Verbose; } } }