DistributedProofreaders / dproofreaders

Distributed Proofreaders is a web application intended to ease the process of converting public domain books into e-texts.
https://www.pgdp.net
GNU General Public License v2.0
46 stars 27 forks source link

Implement standard logging interface #1232

Open cpeel opened 2 weeks ago

cpeel commented 2 weeks ago

PHP has no standard logging interface (unlike Python's robust logging module). All it has is error_log() which dumps a string out to the php_errors file. We use this feature in several places in the code to log things:

$ grep -R error_log *
accounts/activate.php:    error_log("activate.php - Error activating $reg_token: $create_user_status");
api/index.php:        error_log("api/index.php - Error setting $key:count=$count in memcache");
pinc/base.inc:        error_log("base.inc - $error_message");
pinc/DPDatabase.inc:        error_log("DPDatabase.inc - log_error from $caller: $error");
pinc/send_mail.inc:        error_log("send_email.inc - Message could not be sent. PHPMailer Error: {$mail->ErrorInfo}");
pinc/upload_file.inc:        error_log("upload_file.inc - zip error: " . $exception->getMessage());
pinc/upload_file.inc:        error_log($reporting_string);
tasks.php:            error_log("tasks.php - task $tid is linked to non-existent topic $topic_id");
tools/project_manager/add_files.php:                error_log("add_files.php - error running \"$cmd\"; exit code: $exit_status");
tools/upload_resumable_file.php:        error_log("upload_resumable_file.php - $error");

We also have various forms of adhoc logging like DPDatabase->log_trace().

What we need is a logging interface that we can use instead of php_errors for things that aren't actually errors (although they might be) that we want to keep track of. Like the Python logging library it needs to:

There may be existing logging packages out there although I didn't find a lightweight one on packagist.

cpeel commented 2 weeks ago

Correction, I think https://github.com/Seldaek/monolog is a good option here. It has a lot of optional requires but the default set is very small.