log4j basic configuration

Viewed 41339

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);
6 Answers

Assuming you are calling BasicConfigurator.configure() before any loggers are called:

You can use either of these config files to change it without recompiling:

log4j.properties

log4j.rootLogger=INFO

log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <root> 
    <priority value="INFO"/> 
  </root>
</log4j:configuration>

One of these must be on command line.

Related