How to Use change FilePath in log4j appender according environment
Posted By : Ankush Kocher | 19-Nov-2014
In this Blog we see how to use different file path for different environment. We will consider two environment devolepment and production and use file path -
/opt/dev/myLog.log
and /opt/production/myLog.log
respectively.
In config/config.groovy
environments { development { log4j = { appenders { appender new DailyRollingFileAppender( name: 'myFileAppender', datePattern: "'.'yyyy-MM-dd", layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss} %X{sessionId} %X{actionQuery} %n'), file: '/opt/dev/myLog.log' ) } } production { grails.logging.jul.usebridge = false appenders { appender new DailyRollingFileAppender( name: 'myFileAppender', datePattern: "'.'yyyy-MM-dd", layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss} %X{sessionId} %X{actionQuery} %n'), file: '/opt/production/myLog.log' ) } }
alternatively,
def logPath environments { development { logPath = '/opt/dev/myLog.log' } production { grails.logging.jul.usebridge = false logPath = '/opt/production/myLog.log' } log4j = { appenders { appender new DailyRollingFileAppender( name: 'myFileAppender', datePattern: "'.'yyyy-MM-dd", layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss} %X{sessionId} %X{actionQuery} %n'), file: logPath ) } }
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankush Kocher
Ankush is a bright web app developer with expertise in Groovy and Grails development. Ankush is also an expert AngularJS developer.