I use log4j in my spring mvc project and I create log file uing log4j.properties in the following.
# Root logger option
log4j.rootLogger= INFO, info, file, stdout, error
# Direct log messages to a log file [INFO]
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.File=.logs\\mylog.log
log4j.appender.info.Threshold=INFO
log4j.appender.info.MaxFileSize=1Kb
log4j.appender.info.MaxBackupIndex=10
log4j.appender.info.DatePattern='.'yyyy-MM-dd
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I want it to be stored in myapp/logs folder in my web application . what part i should for the file.
here is the directory
Right now it will be saved in the current working directory of your IDE (Eclipse or STS, I guess). Its not a good idea to put the file in the project structure, because that structure wont exist, once you deployed the app anywhere.
In Spring you can define a property in youe web.xml, to make the location variable:
Then add a variable to your config:
If you have to store it in the application, you can also define that programmatically, by makeing use of "ServletContext.getRealPath(".") to find out where your app is deployed, and then set the path to the file.