Skip to content

Slf4jFormatShouldBeConst: tolerate use of simple LOGGER.info(String) #103

@gregallen

Description

@gregallen

This is bad and deserves to be raised as error:

  1. logger.info("blah: " + var);

However, this is sometime tolerable:

  1. logger.info(computeToString(var))

Since the log methods which take no arguments short-cut all the format logic and varargs array creation etc - e.g. see org.slf4j.helpers.MessageFormatter#arrayFormat(java.lang.String, java.lang.Object[], java.lang.Throwable)
Note in particular that with this single argument call slf4j does not parse the passed string for {} placeholders

Hence replacing with this has non-trivial performance impact

logger.info("{}", computeToString(var))

Hence it would be useful if (2) could either be captured by a different check, or permitted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions