-
Notifications
You must be signed in to change notification settings - Fork 11
improve logging #312
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
improve logging #312
Conversation
6c042fb to
1340a9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves error handling and logging by consolidating user-facing error messages into a centralized system and enhancing the error logging functionality with additional metadata.
- Refactored user-facing error message logic from shutdown function to centralized
UnitySite::errorToUsermethod - Enhanced error logging with additional parameters for error IDs, exception objects, and data payloads
- Replaced
enable_shutdown_messageconfig option withenable_error_to_userfor better clarity
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| resources/lib/phpopenldaper | Updated submodule commit to remove JSON pretty-printing |
| resources/lib/UnitySite.php | Core refactoring with new centralized error handling and enhanced logging |
| deployment/overrides/worker/config/config.ini | Updated config option name for worker environment |
| deployment/overrides/phpunit/config/config.ini | Updated config option name for test environment |
| defaults/config.ini.default | Updated default config option name |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
19f216f to
a851f50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cb9db0c to
4b7ca30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
not in this version of PHP no args for die replace enable_shutdown_msg with enable_error_to_user only make popup if content already sent prettier conditionals revert die shorten rearrange Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> use status code for redirect fix type, revert change
4b7ca30 to
6dc21ac
Compare
This is only a slight improvement for #306. In general, I think it makes sense for "forbidden" and "bad request" errors to also make an error popup and generate an error ID.
UnitySite::errorToUserbadRequest,forbiddenUnitySite::errorLogto take new parameterserrorid,error,dataerroridwas only printed from the shutdown function, and it was assumed that the reader would look at the previous message fromerrorLogto correlate it with theerroriddataparameter is used by the shutdown function sinceerror_get_lastdoesn't return aThrowablebut just an array of error infobadRequest,forbiddento take new parameterserror,dataArrayKeyExceptionis one good use for theerrorforbadRequestUnitySite::throwableToArrayfor nice logging of thrown errors/exceptionsJSON_UNESCAPED_SLASHESflagenable_shutdown_messageconfig option with a newenable_error_to_userconfig optionUnitySite::headerResponseCode($code, $reason)withhttp_response_code()example: uncaught exception
before
error log:
[Mon Sep 22 17:27:22.669519 2025] [php:notice] [pid 11] [client 192.168.65.1:26058] internal server error: {"message":"{\\"type\\":1,\\"message\\":\\"Uncaught Exception in \\\\\\/var\\\\\\/www\\\\\\/unity-web-portal\\\\\\/webroot\\\\\\/panel\\\\\\/new_account.php:72\\\\nStack trace:\\\\n#0 {main}\\\\n thrown\\",\\"file\\":\\"\\\\\\/var\\\\\\/www\\\\\\/unity-web-portal\\\\\\/webroot\\\\\\/panel\\\\\\/new_account.php\\",\\"line\\":72,\\"unity_error_id\\":\\"68d186faa3727\\"}","REMOTE_USER":"[email protected]","REMOTE_ADDR":"192.168.65.1","trace":"#0 \\/var\\/www\\/unity-web-portal\\/resources\\/lib\\/UnitySite.php(89): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()\\n#1 [internal function]: UnityWebPortal\\\\lib\\\\UnitySite::shutdown()\\n#2 {main}"}, referer: http://127.0.0.1:8000/json reformatted:
{ "message": "{\\"type\\":1,\\"message\\":\\"Uncaught Exception in \\\\\\/var\\\\\\/www\\\\\\/unity-web-portal\\\\\\/webroot\\\\\\/panel\\\\\\/new_account.php: 72\\\\nStack trace:\\\\n#0 {main}\\\\n thrown\\",\\"file\\":\\"\\\\\\/var\\\\\\/www\\\\\\/unity-web-portal\\\\\\/webroot\\\\\\/panel\\\\\\/new_account.php\\",\\"line\\":72,\\"unity_error_id\\":\\"68d186faa3727\\"}", "REMOTE_USER": "[email protected]", "REMOTE_ADDR": "192.168.65.1", "trace": "#0 \\/var\\/www\\/unity-web-portal\\/resources\\/lib\\/UnitySite.php(89): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()\\n#1 [internal function]: UnityWebPortal\\\\lib\\\\UnitySite::shutdown()\\n#2 {main}" }after
error log:
[Mon Sep 22 17:25:53.470629 2025] [php:notice] [pid 11] [client 192.168.65.1:30990] internal server error: {"message":"An internal server error has occurred.","REMOTE_USER":"[email protected]","REMOTE_ADDR":"192.168.65.1","errorid":"68d186a172e31","trace":["#0 /var/www/unity-web-portal/resources/lib/UnitySite.php(122): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()","#1 /var/www/unity-web-portal/resources/lib/UnitySite.php(138): UnityWebPortal\\\\lib\\\\UnitySite::internalServerError()","#2 [internal function]: UnityWebPortal\\\\lib\\\\UnitySite::shutdown()","#3 {main}"],"data":{"error":{"type":1,"message":["Uncaught Exception in /var/www/unity-web-portal/webroot/panel/new_account.php:72","Stack trace:","#0 {main}"," thrown"],"file":"/var/www/unity-web-portal/webroot/panel/new_account.php","line":72}}}, referer: http://127.0.0.1:8000/index.phpjson reformatted:
{ "message": "An internal server error has occurred.", "REMOTE_USER": "[email protected]", "REMOTE_ADDR": "192.168.65.1", "errorid": "68d186a172e31", "trace": [ "#0 /var/www/unity-web-portal/resources/lib/UnitySite.php(122): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()", "#1 /var/www/unity-web-portal/resources/lib/UnitySite.php(138): UnityWebPortal\\\\lib\\\\UnitySite::internalServerError()", "#2 [internal function]: UnityWebPortal\\\\lib\\\\UnitySite::shutdown()", "#3 {main}" ], "data": { "error": { "type": 1, "message": [ "Uncaught Exception in /var/www/unity-web-portal/webroot/panel/new_account.php:72", "Stack trace:", "#0 {main}", " thrown" ], "file": "/var/www/unity-web-portal/webroot/panel/new_account.php", "line": 72 } } }example: bad request
before
error log:
[Mon Sep 22 17:36:26.948241 2025] [php:notice] [pid 16] [client 192.168.65.1:64646] bad request: {"message":"The selected PI 'foobar'does not exist","REMOTE_USER":"[email protected]","REMOTE_ADDR":"192.168.65.1","trace":"#0 \\/var\\/www\\/unity-web-portal\\/resources\\/lib\\/UnitySite.php(61): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()\\n#1 \\/var\\/www\\/unity-web-portal\\/webroot\\/panel\\/new_account.php(29): UnityWebPortal\\\\lib\\\\UnitySite::badRequest()\\n#2 {main}"}, referer: http://127.0.0.1:8000/panel/new_account.phpjson reformatted:
{ "message": "The selected PI 'foobar'does not exist", "REMOTE_USER": "[email protected]", "REMOTE_ADDR": "192.168.65.1", "trace": "#0 \\/var\\/www\\/unity-web-portal\\/resources\\/lib\\/UnitySite.php(61): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()\\n#1 \\/var\\/www\\/unity-web-portal\\/webroot\\/panel\\/new_account.php(29): UnityWebPortal\\\\lib\\\\UnitySite::badRequest()\\n#2 {main}" }after
error log:
[Mon Sep 22 17:37:38.080828 2025] [php:notice] [pid 11] [client 192.168.65.1:42080] bad request: {"message":"The selected PI 'foobar'does not exist","REMOTE_USER":"[email protected]","REMOTE_ADDR":"192.168.65.1","errorid":"68d1896213b8a","trace":["#0 /var/www/unity-web-portal/resources/lib/UnitySite.php(106): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()","#1 /var/www/unity-web-portal/webroot/panel/new_account.php(29): UnityWebPortal\\\\lib\\\\UnitySite::badRequest()","#2 {main}"]}, referer: http://127.0.0.1:8000/panel/new_account.phpjson reformatted:
{ "message": "The selected PI 'foobar'does not exist", "REMOTE_USER": "[email protected]", "REMOTE_ADDR": "192.168.65.1", "errorid": "68d1896213b8a", "trace": [ "#0 /var/www/unity-web-portal/resources/lib/UnitySite.php(106): UnityWebPortal\\\\lib\\\\UnitySite::errorLog()", "#1 /var/www/unity-web-portal/webroot/panel/new_account.php(29): UnityWebPortal\\\\lib\\\\UnitySite::badRequest()", "#2 {main}" ] }