apache/druid · warning

Not registering log4j shutdown hooks. Not using log4j?

Error message

Not registering log4j shutdown hooks. Not using log4j?

What it means

This warning is the fallback catch in configure(): when log4j API/core classes are absent (ClassNotFoundException), cast to expected log4j types fails (ClassCastException), or linkage fails, the module gives up on registering shutdown hooks. It indicates the process is not running log4j2 as its logging implementation, so Druid cannot perform a managed log4j shutdown.

Solutions

  1. Add org.apache.logging.log4j:log4j-core (matching the log4j-api version) to the runtime classpath
  2. Verify with `mvn dependency:tree` that only one SLF4J provider is present and it is log4j-slf4j-impl
  3. If alternate logging is intentional, treat this as informational and configure shutdown behavior for that provider instead

Example fix

// before (classpath)
log4j-api-2.x.jar  (no core)
// after
log4j-api-2.x.jar
log4j-core-2.x.jar
log4j-slf4j-impl-2.x.jar
Defensive patterns

Strategy: validation

Validate before calling

boolean hasLog4j() { try { Class.forName("org.apache.logging.log4j.core.util.ShutdownCallbackRegistry"); return true; } catch (ClassNotFoundException | LinkageError e) { return false; } }

Type guard

boolean isLog4jAvailable() { try { Class.forName("org.apache.logging.log4j.LogManager"); return true; } catch (Throwable t) { return false; } }

Prevention

When it happens

Trigger: Startup in an environment where org.apache.logging.log4j.LogManager or ShutdownCallbackRegistry cannot be loaded, or the registry/factory casts fail — typically when log4j-core is not on the runtime classpath or an alternate SLF4J provider is bound.

Common situations: Running Druid in a slimmed container without log4j-core, deploying only the API jar, dependency conflicts from extensions pulling in different logging stacks.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/cf868b8b2abef1fb. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/initialization/Log4jShutterDownerModule.java:82

        );
        return;
      }
      final ShutdownCallbackRegistry registry = ((Log4jContextFactory) contextFactory).getShutdownCallbackRegistry();
      if (!(registry instanceof Log4jShutdown)) {
        log.warn(
            "Shutdown callback registry expected class [%s] found [%s]. Skipping shutdown registry",
            Log4jShutdown.class.getName(),
            registry.getClass().getName()
        );
        return;
      }
      binder.bind(Log4jShutdown.class).toInstance((Log4jShutdown) registry);
      binder.bind(Key.get(Log4jShutterDowner.class, Names.named("ForTheEagerness")))
            .to(Log4jShutterDowner.class)
            .asEagerSingleton();
    }
    catch (ClassNotFoundException | ClassCastException | LinkageError e) {
      log.warn(e, "Not registering log4j shutdown hooks. Not using log4j?");
    }
  }


  @ManageLifecycleInit
  @Provides
  public Log4jShutterDowner getShutterDowner(
      Log4jShutdown log4jShutdown
  )
  {
    return new Log4jShutterDowner(log4jShutdown);
  }

  public static class Log4jShutterDowner
  {
    private final Log4jShutdown log4jShutdown;

    public Log4jShutterDowner(Log4jShutdown log4jShutdown)

View on GitHub (pinned to 9b90983fd2)