Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j basic configuration

Tags:

log4j

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); 
like image 825
enguerran Avatar asked Oct 02 '09 12:10

enguerran


People also ask

What is log4j default configuration?

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.

What is the basic thing in log4j?

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.

What is configuration status in log4j2?

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.


1 Answers

I think the simplest way would be:

    Logger.getRootLogger().setLevel(Level.INFO); 
like image 83
Wolfgang Avatar answered Sep 27 '22 21:09

Wolfgang