If you are using Maven add the dependency :
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
Now you have to specify a file that is called 'log4j.properties' which you have to put in the specific directory : ' src/main/resources/log4j.properties '
Here is how the file should look for example :
# Root logger option
log4j.rootLogger=INFO, file, stdout
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
# 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.springlog.Threshold=INFO
log4j.appender.springlog.layout=org.apache.log4j.PatternLayout
log4j.appender.springlog.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:/example/filename.log
log4j.appender.file.MaxFileSize=10MB
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
Now import these :
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Declare a logger variable like this :
final static Logger logger = Logger.getLogger(TheClassYourIn.class);
And use it in the class like this :
logger.info("Well hello world then ");
This way it works for me. I hope that this answer will help you . Good luck !
PS: log4j.appender.file.File='directory' is how you specify where the logs to be stored. If you don't specify a directory and just leave it as filename.log this file will be automaticly created in the project dir.
filename.log
?logging.path=/var/log
as in the docs, but no log file is created there either.