Renato Dinhani
Renato Dinhani

Reputation: 36756

Using log4j, how I do logging to the Windows console?

How I do to the logging go to the Windows console (that black thing, CMD, COMMAND)? I'm trying with ConsoleAppender, but I don't if I doing it right.

private static ConsoleAppender appender = new ConsoleAppender(new PatternLayout());
private Logger database;

Log() {
    BasicConfigurator.configure();
    database = Logger.getLogger("DATABASE");
    database.addAppender(appender);
}

EDIT:
first: this code is a sample, it is bigger than this
second: on the console of Netbeans works perfectly.

Upvotes: 1

Views: 1405

Answers (1)

Gyan
Gyan

Reputation: 12410

You need to setup all the appenders before logging information. Usually the setting up of log4j (including adding appenders) is done during startup of your application.

You should read the documentation here before trying anything more.

Upvotes: 2

Related Questions