Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Nov 22, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

  2. added
    type: bug
    in: core
    on Jan 11, 2019
  3. added this to the 5.0.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions