Grails logging all to one file - grails

I have an issue when i war my grails project to deploy on my production server there is a limitation that i only log to /var/log/tomcat5/catalina.out. This means that i have to make every log including stacktrace write to that one file. I've tried following other examples and it just doesn't seem to work i still get the error "permission denied on stacktrace.log"
This is my log4j config
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appender.stacktractLog = "org.apache.log4j.FileAppender"
appender.'stacktraceLog.File'="/var/log/tomcat5/catalina.out"
appenders {
rollingFile name:'catalinaOut', maxFileSize:1024, fileName:"/var/log/tomcat5/catalina.out"
}
root {
error 'catalinaOut'
additivity = true
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log'
}

Just modify your configuration:
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appenders {
rollingFile name:'catalinaOut', maxFileSize:1024, fileName:"/var/log/tomcat5/catalina.out"
file name: 'stacktrace', file: "/var/log/tomcat5/catalina.out", layout: pattern(conversionPattern: '%c{2} %m%n')
}
root {
error 'catalinaOut'
additivity = true
}
error stacktrace: "StackTrace"
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log'
}

Can't help with your current problem but I suggest you change the rollingFile properties. Current setting will only give a 1kb file that over writes it's self.
try:
rollingFile name:'catalinaOut', maxFileSize:${10*1024*1024},maxBackupIndex:100,fileName:"/var/log/tomcat5/catalina.out"
This will give you 100 10MB files or about a gig worth of logs.

Related

grails does not write to log file

I have the following in my grails config log4j section:
appenders {
file name: "usageAppender", file: "${logDirectory}/onetract3.log"
}
root { error 'stdout', 'usageAppender' }
info usageAppender: "grails.app.services.com.onetract.onetract.UserService"
The file "onetract3.log" is successfully created, however nothing is written to this file.
I can see in the console that the info is handled correctly.
2014-03-09 20:09:06,912 [http-bio-8080-exec-5] INFO onetract.UserService - New candidateRelations for: com.onetract.onetract.Person : 18
Grails version is 2.3.5
Any ideas on why this isn't getting written to the log file?
Edit: 10.03.1014, set additivity to false.
info additivity: false
usageAppender: "grails.app.services.com.onetract.onetract.UserService"
use this
// Example of changing the log pattern for the default console appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}
appenders {
rollingFile name:'myLogFile',
file:'log/myLogFile.log',
threshold: org.apache.log4j.Level.ALL,
maxFileSize:10485760
}
root {
error 'myLogFile'
additivity = true
}
info "grails.app","com.test"
warn "grails.app","com.test"
debug "grails.app","com.test"
error "grails.app","com.test"
fatal "grails.app","com.test"
trace "grails.app","com.test"
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
The problem was due to the following entry:
file: "${logDirectory}/onetract3.log"
Before the application is running, this works, afterwards not.
The workaround is to explicitly tell the appender where the file is, i.e.
file: "logs/onetract/onetract3.log"
This then works.

Grails logging not working

I'm developing a grails 2.3.4 application and had some logging problems.
Actually, I couldn't configure any logging at all (accordingly to http://grails.org/doc/latest/guide/conf.html#logging) - had no output result.
After some brainstorming I figured out, that the grails documentation configs are not working for my project. Nevertheless, some configs variation worked fine (I saw the result on my screen):
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}
root {
error 'stdout'
additivity = true
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
debug stdout: ['edu.dm']
}
The configs like:
debug stdout: ['grails.app.services', 'grails.app.services.edu']
debug stdout: ['grails.app.controllers', 'grails.app.controllers.edu']
failed.
I would be extremely thankful, if anyone could explain my mistakes or share a link with an explanation.
The whole project can be found here: https://github.com/AlexDavljatov/EduDM/tree/master/LoggingMiniProject
Many thanks in advance.
Kind regards,
Alexander Davliatov.
Start like this:
log4j = {
root {
debug()
}
}
You should get a lot of logging to your console. Then (if that works), try this:
log4j = {
info "grails.app"
}
Among the output you should see log.info from your controllers and services. Then slowly add to the config.
Don't forget to restart between the changes in Config.groovy.
This configuration works in Grails 2.3.5 project
// log4j configuration
log4j = {
appenders {
// Use if we want to prevent creation of a stacktrace.log file.
'null' name:'stacktrace'
// Use this if we want to modify the default appender called 'stdout'.
console name:'stdout', layout:pattern(conversionPattern: '%d{yyyy-MM-dd HH:mm} -%x- %-5p-%-10c:%m%n')
// Custom log file.
/* rollingFile name:"appLog",
file:"${globalDirs.logDirectory}${appName}.log".toString(),
maxFileSize:'300kB',
maxBackupIndex:1,
layout:pattern(conversionPattern: '%d{[EEE, dd-MMM-yyyy # HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n')*/
}
// This is for the built-in stuff and from the default Grails-1.2.1 config.
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log' // Jetty
error 'grails.app' // Set the default log level for our app code.
// Move anything that should behave differently into this section.
switch(Environment.current) {
case Environment.DEVELOPMENT:
// Configure the root logger to output to stdout and appLog appenders.
root {
error 'stdout'
//,'appLog'
additivity = true
}
error 'grails.plugin.springsecurity.web.filter.DebugFilter'
error "grails.plugins.twitterbootstrap"
debug "it.mypackage"
debug "org.hibernate.SQL"
debug 'grails.app.controllers'
debug 'grails.app.services'
debug 'grails.app.taglib'
debug 'grails.app.conf'
debug 'grails.app.jobs'
break
case Environment.TEST:
// Configure the root logger to only output to appLog appender.
root {
error 'stdout'
//,'appLog'
additivity = true
}
//depend how much code write in console
// debug 'grails.app.controllers'
// debug 'grails.app.domain'
// debug 'grails.app.services'
// debug 'grails.app.taglib'
// debug 'grails.app.conf'
// debug 'grails.app.filters'
break
case Environment.PRODUCTION:
// Configure the root logger to output to stdout and appLog appenders.
root {
error 'stdout'
//,'appLog'
additivity = true
}
error 'grails.app'
break
}
}
For your grails version (2.3.4 http://grails.github.io/grails-doc/2.3.4/guide/conf.html#logging) it seems the problem is you inherit the configuration level from the root.
To avoid this you need to specify additivity: false
log4j = {
...
debug additivity: false, stdout: ['grails.app.services', 'grails.app.services.edu', 'grails.app.controllers', 'grails.app.controllers.edu']
...
}

log4j SMTPAppender sending mail with empty mail body

In my grails app I have lg4j config as follows
log4j = {
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration,
'net.sf.ehcache.hibernate'
warn 'org.hibernate', 'grails.app', 'org.springframework', 'org.springframework.security'
info 'org.springframework', 'org.springframework.security', 'grails.app'
appenders {
def patternLayout = new PatternLayout()
patternLayout.setConversionPattern("[%r] %c{2} %m%n")
def mailAppender = new SMTPAppender()
mailAppender.setFrom("from#webbfontaine.am")
mailAppender.setTo("to#webbfontaine.am")
mailAppender.setSubject("[Error in application] [host:test.am]")
mailAppender.setSMTPHost("smtp.test.am")
mailAppender.setLayout(patternLayout)
mailAppender.setThreshold(org.apache.log4j.Level.WARN)
appender name:'mail', mailAppender
}
root {
warn 'mail', 'stdout'
}
}
It works fine and sends mail when I run my app with grails run-app, but when I deploy war under tomcat, I get emails with empty body. Is there some specific jar that should be under tomcat/libs? Any ideas?

log4j not working in grails

I have the following configuration for log4j
log4j = {
// Example of changing the log pattern for the default console appender:
//
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}
info 'grails.app.controllers'
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
}
when I do log.info in my controller, I don't see any output being logged in to the console. Any reasons why ?
Just had to add grails.app and that did the trick

Grails empty log file with log4j

it seems that my grails (2.1) log4j config isn't used properly and i can't find the problem.
The log file is created but empty and the stdout doesn't follow my pattern.
log4j = {
appenders {
rollingFile name: "myFileAppender", file: "LogFile.log", maxFileSize: 1024, layout:pattern(conversionPattern: '%d (%t) [%24F:%-3L:%-5p]%x %m%n')
console name: 'myStdoutAppender', layout:pattern(conversionPattern: '%d (%t) [%24F:%-3L:%-5p]%x %m%n')
}
warn 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
debug 'org.my.stuff',
'grails.test',
'grails.app'
root = {
debug 'myFileAppender', 'myStdoutAppender'
additivity = true
}
}
Anyone an idea what i did wrong?
Don't assign to the root logger. Just call it with the supplied closure:
// No equals sign
root {
debug 'myFileAppender', 'myStdoutAppender'
additivity = true
}

Resources