Pregunta

I have to use only slf4j framework in my project instead of log4j. Is there any way to set custom sonar rule to validation logging framework and to show violation if we use log4j.

Of course we can use logj-over-slf4j to avoid compilation errors. But I need to use strictly slf4j.

¿Fue útil?

Solución

Yes, this can be done. (I am assuming you are using Java, correct?)

You can activate the IllegalImport check from the Checkstyle repository in your Java quality profile. Make sure to add org.apache.log4j to the list of illegalPkgs. E.g. set illegalPkgs to sun, com.sun, org.apache.log4j.

Also, in SonarQube, you can activate the Architectural Constraint rule. Here, you must set the toClasses property to a wildcard expression such as org.apache.log4j.**.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top