Olá
Estou tentando fazer o log4j funcionar no console do eclipse
Tenho o arquivo de properties no src do meu projeto.
Porem quando executo a minha classe eu tenho esse erro:
log4j:ERROR Could not find value for key log4j.appender.stdout
log4j:ERROR Could not instantiate appender named “stdout”.
Alguem saberia me dizer o que ta rolando de errado?
Eu só quero mostrar a seguinte mensagem em meu console :
log.info(“entrei no metodo main da classe Log4JDemo”);
Grato
===========log4j.properties====================
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=warn, stdout
=======================classe java para executar com erro==============
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
public class Log4JDemo
{
static final Category log = Category.getInstance(Log4JDemo.class);
static final String LOG_PROPERTIES_FILE = "log4j.properties";
public static void main(String[] args)
{
log.info("entrei no metodo main da classe Log4JDemo");
}
public Log4JDemo()
{
initializeLogger();
log.info( "Log4JDemo - leaving the constructor ..." );
}
private void initializeLogger()
{
Properties logProperties = new Properties();
try
{
logProperties.load(new FileInputStream(LOG_PROPERTIES_FILE));
PropertyConfigurator.configure(logProperties);
log.info("Logging initialized.");
}
catch(IOException e)
{
throw new RuntimeException("Unable to load logging property " + LOG_PROPERTIES_FILE);
}
}
}