Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 22, 2017 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 22, 2017

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Alright, fixed in master. Please give it a try...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants