I am working on a project with legacy code that had used Log4J in the past, and now uses SLF4J. Most of the old style Log4J logging statements remain, and I convert the log statements slowly to the new SLF4J style as I come across them.
I've just realised that pressing Alt+Enter when in the old style log statements gives me the following options (unfortunately I cannot upload a screenshot):
The option Replace '+' with 'String.format()'
is very close to what I need, although I don't need the String.format(
bit.
Is there something that would give me an Intention Action of: Replace Log4J style log statement with SLF4J style log statement
?
As an example of old logging style (e.g. Log4J), I mean:
LOGGER.debug("User " + user.getUserId() + " has performed a search with the criteria " + dto);
And by new style I mean:
LOGGER.debug("User {} has performed a search with the criteria {}", user.getUserId(), dto);
As we have previously announced, the IDEs based on the IntelliJ Platform are not affected by this vulnerability, because they use a patched version of log4j 1.2 with all network-related code removed.
This is the main purpose of SLF4J (Simple Logging Facade for Java) – a logging abstraction which helps to decouple your application from the underlying logger by allowing it to be plugged in – at runtime. Of course, the flexibility that such an abstraction provides is the main reason to use SLF4J.
SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP.
To disable this behavior, you must add a logback configuration file called logback. xml in your java classpath root. You can download this minimal logback. xml file and add it in the src/main/resources directory for a maven project or beside fr directory for a simple java project.
Have you tried the Java | Logging issues | Non-constant string concatenation as argument to logging call inspection? It has a quickfix to automatically convert a string concatenation to a parameterized log message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With