import org.apache.log4j.Logger; public class MyClass { private static final Logger logger = Logger.getLogger(MyClass.class); public static void main(String[] args) { // set logging level to INFO logger.setLevel(Level.INFO); // rest of the code... } }
import org.apache.log4j.Level; public class MyCustomLevel extends Level { public MyCustomLevel(int level, String levelStr, int syslogEquivalent) { super(level, levelStr, syslogEquivalent); } public static final int MY_CUSTOM_LEVEL_INT = Level.INFO_INT + 1; public static final String MY_CUSTOM_LEVEL_STR = "MY_CUSTOM_LEVEL"; public static final MyCustomLevel MY_CUSTOM_LEVEL = new MyCustomLevel(MY_CUSTOM_LEVEL_INT, MY_CUSTOM_LEVEL_STR, 7); }In this example, we create a custom MyCustomLevel that extends the Level class. We define a custom int value, string value, and syslog equivalent for this level. Package Library: org.apache.log4j