JavaCokyMan 2014-08-25
Grails(24)Grails Deploying and Logging with Tomcat
1. Tomcat Configuration
DB configuration in conf/conext.xml
<Resource name="jdbc/lmm" auth="Container" type="javax.sql.DataSource"
maxIdle="30" maxWait="-1" maxActive="100"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testOnBorrow="true"
validationQuery="select 1"
logAbandoned="true"
username="root"
password=“password"
driverClassname="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sillycat?autoReconnect=true&useServerPrepStmts=false&rewriteBatchedStatements=true"/>
Change the bin/catalina.sh to fix the out of memory issue
export JAVA_OPTS="-Xms1024m -Xmx2046m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m -Dbuild.env=lmm.local"
2. Grails Logging
grails logging is controller by BuildConfig.groovy or some other groovy files. The content part should be as follow>
import org.apache.log4j.PatternLayout
import org.apache.log4j.Level
import org.apache.log4j.DailyRollingFileAppender
log4j = {
def logLayoutPattern = new PatternLayout("%d [%t] %-5p %c %x - %m%n")
appenders {
rollingFile name: "stacktrace", file: "/var/log/sillycat/stacktrace.log", maxBackupIndex: 5, threshold: Level.ERROR, layout:logLayoutPattern
console name: "stdout", threshold: Level.DEBUG, layout: logLayoutPattern
rollingFile name: "appFile", file: "/var/log/sillycat/appDebug.log", maxBackupIndex: 5, threshold: Level.ERROR, layout: logLayoutPattern
appender(new ScrubbingAppender(
name: "scrub",
threshold: Level.ERROR,
layout: logLayoutPattern,
regex: "^(com.sillycat).*\$"
))
appender new DailyRollingFileAppender(
name: "pushnotifications",
threshold: Level.ERROR,
layout: logLayoutPattern,
datePattern: "'.'yyyy-MM-dd-a",
file: "/var/log/sillycat/pushnotifications.log"
)
}
error appFile: [
'com.sillycat',
'grails.app.test.integration.com.sillycat.lmm.security',
'grails.app.service.com.sillycat.lmm.geoFences',
'grails.app.service.com.sillycat.lmm.events',
'grails.app.controller.com.sillycat',
'grails.app.bootstrap.com.sillycat',
‘grails.app.jobs'
],
stdout: [
'com.sillycat',
'com.sillycat.lmm.geoFences',
'com.sillycat.lmm.events',
'grails.app.service.com.sillycat.lmm.geoFences',
'grails.app.test.integration.com.sillycat.lmm.security',
'grails.app.service.com.sillycat.lmm.events',
'grails.app.controller.com.sillycat',
'grails.app.bootstrap.com.sillycat',
'grails.app.jobs.com.sillycat'],
pushnotifications: [
'com.sillycat.lmm.pushNotifications',
'grails.app.service.com.sillycat.lmm.events.StoreAnnouncementEventService',
'grails.app.service.com.sillycat.lmm.campaigns.StoreAnnouncementCampaignService',
'grails.app.service.com.sillycat.lmm.campaigns.BroadcastCampaignService',
'grails.app.service.com.sillycat.lmm.events.PushCallbackEventService',
'com.sillycat.lmm.campaigns.BroadcastCampaignService',
'com.sillycat.lmm.events.StoreAnnouncementEventService',
'grails.app.service.grails.plugin.executor']
root {
info 'scrub'
}
}
Pay attention to this line
rollingFile name: "stacktrace", file: "/var/log/sillycat/stacktrace.log", maxBackupIndex: 5, threshold: Level.ERROR, layout:logLayoutPattern
If I did not configure that it will automatically create a log file under tomcat command runtime directory or our grails command runtime directory.
3. Tomcat Logging Configuration
Logging file conf/logging.properties
I turn them off
1catalina.org.apache.juli.FileHandler.level = OFF
There are 7 level of the log
SERVRE(highest) > WARNING>INFO>CONFIG>FINE>FINER>FINEST
For example:
1catalina.org.apache.juli.FileHandler.level = OFF
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.level = ALL
References:
http://huangrongyou.iteye.com/blog/1577508
http://stackoverflow.com/questions/6132095/problem-with-stacktrace-log-while-deploying-grails-app
http://stackoverflow.com/questions/15523510/permgen-space-error-when-deploying-tomcat-7
http://tomcat.apache.org/tomcat-7.0-doc/logging.html