Reputation: 2663
I am getting this error
log4j:WARN No appenders could be found for logger (com.company.Main).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
This is my Main
package com.company;
import org.apache.log4j.Logger;
public class Main {
final static Logger logger = Logger.getLogger(Main.class);
public static void main(String[] args) {
if(logger.isDebugEnabled()){
logger.debug("This is debug");
}
//logs an error message with parameter
logger.error("This is error");
}
}
While this is my log.properties file
# Root logger option
log4j.rootLogger = DEBUG, stdout, file
# Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File = C:\\log4j-application.log
log4j.appender.file.MaxFileSize = 5MB
log4j.appender.file.MaxBackupIndex = 10
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
and this is my file structure.
I am in learning stage of Log4J and trying to implement a dummy project to understand it deeply.
Upvotes: 1
Views: 7837
Reputation: 69440
You have to add your ressources
directory to your classpath. After that it should work.
Upvotes: 2