Skip to content

(doc) Clarify the usage of parameterized logging in Log4j 2 API page #1918

@ppkarwasz

Description

@ppkarwasz

The Log4j 2 API documentation page could be improved to state that:

  • parameterized logging and string concatenation should not be mixed, e.g.:
    // This is discouraged, but fine:
    logger.info("Hello " + name + "!");
    // This is recommended:
    logger.info("My name is {}.", myName);
    // Mixing the two approaches: a recipe for pattern specifier injection:
    // E.g. if name contains '{}'.
    logger.info("Hello " + name + "! My name is {}.", myName);
  • we could replace the usage of LogManager.getFormatterLogger(Class) with LogManager.getLogger(Class, MessageFormatter), which is more generic.

Metadata

Metadata

Assignees

Labels

documentationPull requests or issues that affect documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions