Reputation: 5764
I'm trying to use log4j in my Java application (no web-app). Therefore I added the configuration file directly within my /src folder.
log4j.properties
log4j.rootLogger=DEBUG
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
My main class is in a package with a sub-namespace and within there I'm trying to log as follows:
final static Logger logger = Logger.getLogger(MainClass.class);
public static void main(String[] args) {
//BasicConfigurator.configure();
logger.warn("some warning");
}
But still I'm getting an error message and I don't know what to do. You see the commented line BasicConfigurator above. As far as I know, the log4j.properties should be read without calling that line, right?
log4j:WARN No appenders could be found for logger (at.company.project.poi.MainClass). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Upvotes: 0
Views: 1638
Reputation: 2978
According to documentation, file should be on classpath and named 'log4j2.properties'
You can also set directly the configuration by setting -Dlog4j.configurationFile="<your config filepath>"
Source: https://logging.apache.org/log4j/2.x/manual/configuration.html
Upvotes: 0