SLF4J is an abstract layer designed for logging
framework, which makes logging platform independent from any specific logging
implementation like Java util logging or Log4j.
Log4J is implementation of logging framework that is
widely used in the industry but some of the most important feature of SLF4J
convinced to use SLF4J like parameterized logging rather than concatenation of
string in log4j and less memory consumption and high performance. In logging
there is always a memory concerns but in SLF4J reduce the memory consumption
and hence increase the performance of the application.
Apart from the above feature the most important
thing is that it gives us freedom to apply any logging framework whenever
required without changing of code to the running application because it is an
abstract layer to provide logging implementations.
See below how to use SLF4J.
Public class Test {
private final Logger
slf4j = LoggerFactory.getLogger(Test.class);
public
void Test(String
name) {
slf4j.info("Hi,
{}", name);//Parameterized logging rather than
slf4j.info("Hello
SLF4J.");// concatenation of log4j.
}
}
For more details please click here.