I have configured the log4j application in the application to send emails in case of any exceptions.
The code looks like this: Config.groovy :
log4j = {
appenders {
String currentUrl = grails.serverURL
String currentEnv = 'Production'
if (Environment.isDevelopmentMode()) {
currentEnv = 'Development'
} else if (currentUrl.indexOf('test') > -1) {
currentEnv = 'Testing'
}
console name: 'stdout', layout: pattern(conversionPattern: '[%r] %c{2} %m%n')
// if real password is needed, please contact IT department
def patternLayout = new PatternLayout()
patternLayout.setConversionPattern("[%r] %c{2} %m%n")
def mailAppender = new SMTPAppender()
mailAppender.setSMTPUsername('a@abc.com')
mailAppender.setSMTPPassword('password')
mailAppender.setFrom("x@xyz.com")
mailAppender.setTo("user@domain.com")
mailAppender.setSubject("A log4j error has been generated in the [${currentEnv}] environment.")
mailAppender.setSMTPHost("smtp.elasticemail.com")
mailAppender.setSMTPPort(2525)
mailAppender.setBufferSize(4096)
mailAppender.setLayout(patternLayout)
appender name: 'mail', mailAppender
root {
error 'stdout', 'mail'
additivity = true
}
}
}
I want to include in the topic, the current login user from which the screen error occurred. I am using spring security plugin and grails version is 1.3.7
I have the following code:
def user
grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent = { e, appCtx ->
user = org.abc.com.Person.get(appCtx.springSecurityService.currentUser.id)
}
outside log4j and the user object instance used, but it returns null.
This is their other way to get the current user in the topic.
How to do it? Please suggest
Also is there a way to send asynchronous mail?
source
share