Voici un exemple de mon Config.groovy basé sur Article sur Burt Beckwith
mail.error.server = 'smtp.yandex.ru' // or 'smtp.gmail.com'
mail.error.port = 465 // or 587 for gmail
mail.error.username = 'do.not.reply@example.com'
mail.error.password = 'site email password'
mail.error.to = 'admin.email@gmail.com'
mail.error.from = "${appName} <${mail.error.username}>"
mail.error.subject = "[Application Error] ${appName} on ${grails.serverURL}"
mail.error.starttls = true
mail.error.protocol = 'smtps' // 'smtps' for secure protocol (SSL)
mail.error.debug = false
/*
The nice thing in this Appender is that you can send email alerts containing more than just your Exception.
You can also add lines that were logged before the exception.
This will make it much easier to understand the cause of your exception.
The number of log lines that will be sent can be determine by “BufferSize” property.
For example: if BufferSize=10, then your email will also contain the 9 lines logged before the exception.
default 512
*/
mail.error.bufferSize = 512
// log4j configuration
log4j = {
appenders {
// stdout, default console appender
appender new ConsoleAppender(name: 'stdout',
threshold: Level.TRACE,
layout: simple)
// main
appender new RollingFileAppender(name: 'main',
threshold: Level.TRACE,
layout: pattern(conversionPattern: '%d %c{2} %-5p %m%n'),
file: "/var/log/${appName}/main.log",
maxFileSize: 1024
)
// To send all errors or bigger level messages in email via SMTPAppender
// Careful. If your SMTP server goes down, you may run into a thread deadlock scenario.
System.setProperty 'mail.smtp.port', config.mail.error.port.toString()
System.setProperty 'mail.smtp.starttls.enable', config.mail.error.starttls.toString()
appender new SMTPAppender(name: 'smtp',
threshold: Level.INFO,
layout: pattern(conversionPattern: '%d{[ dd.MM.yyyy HH:mm:ss.SSS]} [%t] %n%-5p %n%c %n%C %n %x %n %m%n'), // %5p: %d{dd MMM yyyy, HH:mm:ss} - %m%n'
to: config.mail.error.to,
from: config.mail.error.from,
subject: config.mail.error.subject,
SMTPHost: config.mail.error.server,
SMTPUsername: config.mail.error.username,
SMTPDebug: config.mail.error.debug.toString(),
SMTPPassword: config.mail.error.password,
SMTPProtocol: config.mail.error.protocol,
bufferSize: config.mail.error.bufferSize
)
}
all 'grails.app' // Logging all for all application artifacts
info 'grails.app.conf', // For anything under grails-app/conf such as BootStrap.groovy (but excluding filters)
'grails.app.filters', // For filters
'grails.app.taglib', // For tag libraries
'grails.app.services', // For service classes
'grails.app.controllers', // For controllers
'grails.app.domain' // For domain entities
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web', // Grails web request processing
'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', // See what Spring is doing
'org.hibernate', // See what Hibernate is doing
'net.sf.ehcache.hibernate'
// Enable Hibernate SQL logging with param values
trace 'org.hibernate.type'
debug 'org.hibernate.SQL'
environments {
development {
// Override previous setting for 'grails.app.controller'
all 'grails.app'
root {
all 'stdout'
}
//NOTE target/stacktrace.log would be created anyway
}
test {
// Override previous setting for 'grails.app.controller'
info 'grails.app'
root {
info 'stdout'
}
//NOTE target/stacktrace.log would be created anyway
}
production {
// Override previous setting for 'grails.app.controller'
warn 'grails.app'
root {
warn 'main', 'smtp'
additivity = true
}
}
}
}