Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement standard logging interface #1232

Open
cpeel opened this issue Jun 10, 2024 · 1 comment
Open

Implement standard logging interface #1232

cpeel opened this issue Jun 10, 2024 · 1 comment
Labels
infra Infrastructure - plumbing is fun

Comments

@cpeel
Copy link
Member

cpeel commented Jun 10, 2024

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:

  • honor logging levels (error, warning, info, debug)
  • configure logging levels for individual classes or modules
  • be simple for consumers to use (eg: DPLogger::info("log this message"))

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

@cpeel
Copy link
Member Author

cpeel commented Jun 10, 2024

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.

@cpeel cpeel added the infra Infrastructure - plumbing is fun label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra Infrastructure - plumbing is fun
Projects
None yet
Development

No branches or pull requests

1 participant