Skip to content

commons-logging LogFactory and String arguments [SPR-16226] #20774

@spring-projects-issues

Description

@spring-projects-issues

Gary Russell opened SPR-16226 and commented

@SpringBootApplication
public class Slf4jApplication {

	private static final Log commonsLogger = LogFactory.getLog(Slf4jApplication.class);

	private static final Logger slf4jLogger = LoggerFactory.getLogger(Slf4jApplication.class);

	public static void main(String[] args) {
		Map<?, ?> emptyMap = new HashMap<>();
		String message = "map contents: " + emptyMap.toString();
		commonsLogger.warn(message);
		slf4jLogger.warn(message);
	}

}

Results in an improper argument expansion due to Log4j internal use of ReusableObjectMessage.

11:40:05.265 [main] WARN com.example.Slf4jApplication - map contents: map contents: {}
11:40:05.267 [main] WARN com.example.Slf4jApplication - map contents: {}

If log4j-api is on the class path.

If LogFactory.Log4jLog methods tested for a String and called the appropriate method, Log4j would use a ReusableSimpleMessage instead, which doesn't suffer from this problem.


Affects: 5.0.1

Issue Links:

Referenced from: commits 93f17da

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions