progress output on stdout when emails are processed as activities
On a CiviCRM instance I administrate, the Civi cron job is run via “cv api job.execute” with appropriate user and cwd parameters. The output is normally in JSON, so I decided to parse the output to see if there have been any problems. If there are no problems, I suppress the output completely, to prevent Linux cron (which triggers the whole thing) from sending an automatic email to the admins. This has worked well so far.
For a short while we have defined two new email accounts that we use for “email to activity”. When there are new emails, we now get output on stdout that makes it impossible to parse the output as JSON. This prevents making the automatic decision on whether there has been a problem, so I revert to sending an email and I keep the output.
I looked into the cause and found that CRM/Utils/Mail/EmailProcessor.php contains several lines that write to stdout. To me these outputs should better go to the CiviCRM log or to stderr. But I don’t know what standards you follow for this or other components, so at this point I am not able to submit a pull request.
You can find the output I am referring to by searching CRM/Utils/Mail/EmailProcessor.php for the string “echo”. I quote them here, together with my opinion of what I would do with them (biased because of my current problem of course):
212 catch (Exception $e) {
213 echo $e->getMessage();
214 $store->markIgnored($key);
215 continue;
216 }
This seems better placed on stderr or as an error entry in the Civi log.
229 echo "Failed Processing: {$mail->subject}. Reason: {$result['error_message']}\n";
Same as above.
234 echo "Processed as Activity: {$mail->subject}\n";
This is the line I regularly get. I think a Civi log entry with an appropriate level below warning should be enough, or it should go to stderr.
391 echo "Failed Processing: {$mail->subject}, Action: $action, Job ID: $job, Queue ID: $queue, Hash: $hash. Reason: {$r esult['error_message']}\n";
Same as earlier, error entry in the Civi log or stderr
These lines have been around for many years (I checked), and there might be similar examples in several other places. Again, I don’t know what your conventions are.