SugarCRM and log4php

I spent a lot of time to try to configure log4php in SugarCRM to send email if log even has level WARN, ERROR or FATAL. I made log4php configuration like that:

# Log file appender
....
# Email appender
log4php.appender.A3=LoggerAppenderMail
log4php.appender.A3.layout=LoggerPatternLayout
log4php.appender.A3.layout.ConversionPattern="[%d{d/m/Y H:i:s}] [%p] [%c] %n%n%m%n"
log4php.appender.A3.to=my@email.addr
log4php.appender.A3.from=crmdev@email.addr
log4php.appender.A3.subject="CRM Dev Exception!"

log4php.rootLogger=WARN, A2, A3

It seemes correct but it doen’s work (file logging is working)! One of my colleage Sergey helped me to resolve that problem. LoggerAppenderMail sends one email for all exceptions which appeared during session (it doesn’t send separate message for each exception). To send email at the end of session it needs to close logger:

$logger->shutdown();

Without calling shutdown email won’t be sent!

Leave a Reply

Your email address will not be published. Required fields are marked *