Mailing Exception logs in a live Grails webapp

前端 未结 3 491
有刺的猬
有刺的猬 2021-02-04 21:24

I\'d like my Grails web-app to send an e-mail for each exception that reaches the end-user.

Basically I\'m looking for a elegant way to achieve something equivalent to:<

3条回答
  •  猫巷女王i
    2021-02-04 21:40

    Turns out this exact question was answered on the Grails mailing list a couple of days ago.

    The solution is to add the following to the log4j-section of Config.groovy:

    log4j {
        ...
        appender.mail='org.apache.log4j.net.SMTPAppender'
        appender.'mail.To'='email@example.com'
        appender.'mail.From'='email@example.com'
        appender.'mail.SMTPHost'='localhost'
        appender.'mail.BufferSize'=4096
        appender.'mail.Subject'='App Error'
        appender.'mail.layout'='org.apache.log4j.PatternLayout'
        appender.'mail.layout.ConversionPattern'='[%r] %c{2} %m%n'
        rootLogger="error,stdout,mail"
        ...
        // rootLogger="error,stdout" (old rootLogger)
    }
    

    Plus adding sun-javamail.jar and activation.jar to the lib/-folder.

提交回复
热议问题