I used log4j to log some steps in my application. To be quick and dirty, I used:
org.apache.log4j.BasicConfigurator.configure();
This output my logs in the Eclipse console.
I want to know if and how to set the level threshold higher than DEBUG? In other word, I do not want to display DEBUG level message, just ERR, WARN, INFO.
Thank you.
EDIT: May I use this following?
import org.apache.log4j.Logger; import org.apache.log4j.Level; [...] Logger logger = Logger.getLogger(this.class); logger.setLevel(Level.INFO);
Log4j will provide a default configuration if it cannot locate a configuration file. The default configuration, provided in the DefaultConfiguration class, will set up: A ConsoleAppender attached to the root logger. A PatternLayout set to the pattern "%d{HH:mm:ss.
Log4j has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.
I think the simplest way would be:
Logger.getRootLogger().setLevel(Level.INFO);
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