Reputation: 1
This is my log4j.properties
# Define the root logger with appender file
log4j.rootLogger = DEBUG,FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=/media/.I have given the whole path../MyProject/log.log
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
This is my java file
package examples;
import java.util.logging.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Test {
static Logger logger = Logger.getLogger(Test.class.getName());
public static void main(String a[]){
//PropertiesConfigurator is used to configure logger from properties file
PropertyConfigurator.configure("log4j.properties");
//Log in console in and log file
//logger.debug("Log4j appender configuration is successful !!");
logger.info("Log4j appender configuration is successful !!");
}
}
Still i m getting output message on console only my log.log file is empty. I have write permissions to the file I am running this in eclipse is that a problem.
Upvotes: 0
Views: 5455
Reputation: 1349
Use Logger from log4j package.
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
Create your logger like this :
static final Logger logger = LogManager.getLogger(Test.class.getName());
log4j doesn't catch java.util.logging log messages.
Upvotes: 2