我正在尝试提供自定义日志文件的相对路径。但它不起作用,如果我从完整的路径给出它工作正常。
我的代码是这样的:
log4j = {
appenders {
// append new appenders of your own and add log level and packages/files like to add.
rollingFile name: "myAppender",
maxFileSize: 1024,
file: "C:/GrailsWS/BaseGrails/target/basegrails.log" // WORKING
//"basegrails.log" // NOT WORKING
//"/target/basegrails.log" // NOT WORKING
/*console name: "myAppender",
layout: pattern(conversionPattern: "%c{2} %m%n")*/
}
debug myAppender: 'com.nagarro.base.grails.EmployeeController'
}
我尝试了以上方法,但它无效。
答案 0 :(得分:0)
在tomcat / jetty的日志目录中写入日志,或者如果使用run-app启动,则在项目根目录中写入日志我使用它(如果有帮助):
String logName = “myapp.log"
String logDirectory
// getting tomcat dir
logDirectory = System.getProperty('catalina.base') ? "${System.getProperty('catalina.base')}/logs/" : ''
// getting jetty dir
if (System.getProperty('jetty.home') != null) {
logDirectory = System.getProperty('jetty.home') ? "${System.getProperty('jetty.home')}/logs/" : ''
}
println("CONFIG:Writing log ${logName} in dir:" + logDirectory)
// log4j configuration
log4j = {
appenders {
appender new DailyRollingFileAppender(
name: 'file', datePattern: "'.'yyyy-MM-dd",
file: logDirectory + logName
)}
...