From 53d530f126eb05aa0513621ea4c7c3a6525d1ef7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 30 Mar 2023 14:48:04 +0200 Subject: [PATCH] More data into log --- htdocs/core/class/CMailFile.class.php | 15 +++++++++++---- htdocs/core/lib/functions.lib.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index e350cae47bc..3c732f84bf4 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -849,7 +849,7 @@ class CMailFile dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); if (!empty($conf->global->MAIN_MAIL_DEBUG)) { - $this->save_dump_mail_in_err(); + $this->save_dump_mail_in_err('Mail with topic '.$this->subject); } } else { dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); @@ -1030,7 +1030,7 @@ class CMailFile $res = false; if (!empty($conf->global->MAIN_MAIL_DEBUG)) { - $this->save_dump_mail_in_err(); + $this->save_dump_mail_in_err('Mail with topic '.$this->subject); } } } @@ -1170,7 +1170,7 @@ class CMailFile $res = false; if (!empty($conf->global->MAIN_MAIL_DEBUG)) { - $this->save_dump_mail_in_err(); + $this->save_dump_mail_in_err('Mail with topic '.$this->subject); } } else { dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); @@ -1281,13 +1281,20 @@ class CMailFile * Save content if mail is in error * Used for debugging. * + * @param string $message Add also a message * @return void */ - public function save_dump_mail_in_err() + public function save_dump_mail_in_err($message = '') { global $dolibarr_main_data_root; if (@is_writeable($dolibarr_main_data_root)) { // Avoid fatal error on fopen with open_basedir + // Add message to dolibarr_mail.log + if ($message) { + dol_syslog($message, LOG_DEBUG, 0, '_mail'); + } + + // Move dolibarr_mail.log into a dolibarr_mail.err or dolibarr_mail.date.err $srcfile = $dolibarr_main_data_root."/dolibarr_mail.log"; if (getDolGlobalString('MAIN_MAIL_DEBUG_ERR_WITH_DATE')) { $destfile = $dolibarr_main_data_root."/dolibarr_mail.".dol_print_date(dol_now(), 'dayhourlog', 'gmt').".err"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3d57dc9f50c..dc1f39aa43a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1661,7 +1661,7 @@ function dol_ucwords($string, $encoding = "UTF-8") * On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr * On Linux LOG_ERR=3, LOG_WARNING=4, LOG_NOTICE=5, LOG_INFO=6, LOG_DEBUG=7 * @param int $ident 1=Increase ident of 1 (after log), -1=Decrease ident of 1 (before log) - * @param string $suffixinfilename When output is a file, append this suffix into default log filename. + * @param string $suffixinfilename When output is a file, append this suffix into default log filename. Example '_stripe', '_mail' * @param string $restricttologhandler Force output of log only to this log handler * @param array|null $logcontext If defined, an array with extra informations (can be used by some log handlers) * @return void