apache/beam · error · IllegalArgumentException

Unsupported log level

Error message

Unsupported log level: {level}

What it means

LogElements.log dispatches on the configured Level; if the level is not one of TRACE..ERROR it throws IllegalArgumentException('Unsupported log level: ' + level). Only the five standard levels are accepted.

Solutions

  1. Pass one of Level.TRACE, DEBUG, INFO, WARN, or ERROR.
  2. Validate/map custom levels before calling log(); default unexpected values to INFO.
  3. Null-check the level and substitute a safe default.

Example fix

// before
LogElements.log(myLevel, msg); // myLevel may be custom/null
// after
Level lvl = (myLevel == null) ? Level.INFO : myLevel;
LogElements.log(lvl, msg);
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<Level> ALLOWED = EnumSet.of(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
if (level == null || !ALLOWED.contains(level)) level = Level.INFO;

Type guard

static boolean isSupportedLogLevel(Level l) {
  return l != null && (l == Level.TRACE || l == Level.DEBUG || l == Level.INFO || l == Level.WARN || l == Level.ERROR);
}

Try / catch

try {
  LogElements.log(level, msg);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unsupported log level")) {
    LogElements.log(Level.INFO, msg);
  }
}

Prevention

When it happens

Trigger: Calling LogElements.log(level, ...) or withLevel with null, a custom Level (e.g. FATAL), or an unknown enum value.

Common situations: Mapping an application-level log enum to Beam's Level and falling through with a default; passing a level parsed from config that is out of range; passing null.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/3faee46fc7ceef3b. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/LogElements.java:171

  static void log(Level level, String message) {
    switch (level) {
      case TRACE:
        LOG.trace("{}", message);
        break;
      case DEBUG:
        LOG.debug("{}", message);
        break;
      case INFO:
        LOG.info("{}", message);
        break;
      case WARN:
        LOG.warn("{}", message);
        break;
      case ERROR:
        LOG.error("{}", message);
        break;
      default:
        throw unsupportedLogLevel(level);
    }
  }

  private static boolean isLoggingEnabled(Level level) {
    switch (level) {
      case TRACE:
        return LOG.isTraceEnabled();
      case DEBUG:
        return LOG.isDebugEnabled();
      case INFO:
        return LOG.isInfoEnabled();
      case WARN:
        return LOG.isWarnEnabled();
      case ERROR:
        return LOG.isErrorEnabled();
      default:
        throw unsupportedLogLevel(level);
    }

View on GitHub (pinned to 12126d8942)