Skip to content

Actuator loggers list endpoint throws exception on Log4J2 loggers with custom log levels #35227

Closed
@miladamery

Description

@miladamery

We are using Log4j as our logging framework. One of our loggers has custom Log level. When calling actuator /loggers endpoint to get list of all loggers exception raises:
EffectiveLevel must not be null

This error is from LoggerConfiguration class constructor which doesnt let null values on effectiveLevel variable:

public LoggerConfiguration(String name, LogLevel configuredLevel, LogLevel effectiveLevel) {
		Assert.notNull(name, "Name must not be null");
		Assert.notNull(effectiveLevel, "EffectiveLevel must not be null");
		this.name = name;
		this.configuredLevel = configuredLevel;
		this.effectiveLevel = effectiveLevel;
	}

but the real problem comes when calling this class constructor. in Log4J2LoggingSystem.convertLoggerConfig:

private LoggerConfiguration convertLoggerConfig(String name, LoggerConfig loggerConfig) {
		if (loggerConfig == null) {
			return null;
		}
		LogLevel level = LEVELS.convertNativeToSystem(loggerConfig.getLevel());
		if (!StringUtils.hasLength(name) || LogManager.ROOT_LOGGER_NAME.equals(name)) {
			name = ROOT_LOGGER_NAME;
		}
		boolean isLoggerConfigured = loggerConfig.getName().equals(name);
		LogLevel configuredLevel = (isLoggerConfigured) ? level : null;
		return new LoggerConfiguration(name, configuredLevel, level);
	}

The LEVELS variable:

private static final LogLevels<Level> LEVELS = new LogLevels<>();

	static {
		LEVELS.map(LogLevel.TRACE, Level.TRACE);
		LEVELS.map(LogLevel.DEBUG, Level.DEBUG);
		LEVELS.map(LogLevel.INFO, Level.INFO);
		LEVELS.map(LogLevel.WARN, Level.WARN);
		LEVELS.map(LogLevel.ERROR, Level.ERROR);
		LEVELS.map(LogLevel.FATAL, Level.FATAL);
		LEVELS.map(LogLevel.OFF, Level.OFF);
	}

is like above. Our custom log level doesn't exist in this Map. so this line returns null

LogLevel level = LEVELS.convertNativeToSystem(loggerConfig.getLevel());

and we get the exception.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions