logginglog4jlog4j2slf4jslf4j-api

Custom Level Logging in SLF4J


In my project logging is working perfectly fine. Using Slf4j for logging. Sample is as follows:

 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 public class MyClass{
   private static Logger logger = LoggerFactory.getLogger(MyClass.class);

   public static void main(String...args){
     logger.error("error log...");
   }
 }

we have used log4j2.xml for logging configuration. Now my requirement is to make a custom level log "VERBOSE" having int value 150. I am trying hard but it seems difficult or I dont know if slf4j has flexibility to provide the custom level logging. Please assist.


Solution

  • The Log4j2 API has that capability. SLF4J does not. However, while not equivalent, you could add a VERBOSE Marker to the events and filter on that.