framework
framework copied to clipboard
Single-quoted strings with [ ] in Laravel Log interpreting escape characters (\r \n)
Laravel Version
11.30.0
PHP Version
8.3.13 64bit TS
Database Driver & Version
No response
Description
When logging with single-quoted ' strings that containing escape characters like \r and [ ], they are being interpreted in the log output. This results in unexpected behavior, such as \r being converted to a carriage return, even though single-quoted strings in PHP treat backslashes as literal characters.
Using Illuminate\Support\Facades\Log With default logging configuration.
Steps To Reproduce
1- Download and create a Laravel 11 application project. (https://laravel.com/docs/11.x)
2- In any route, controller, or model file, log a string using single-quotes with a backslash \r and bracket [ ].
Example:
Log::info('[MyNamespace\routes\non-web\application]');
3- Check the Laravel log file.
Expected output
local.INFO: [MyNamespace\routes\non-web\application]
Actual output
local.INFO: [MyNamespace outes on-web\application]
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
I think the issue here is caused by this: https://github.com/Seldaek/monolog/blob/32e515fdc02cdafbe4593e30a9350d486b125b67/src/Monolog/Formatter/LineFormatter.php#L241
If the first character in the log is [ or { then it replaces those substrings with "\n"
Since the formatting is handled by Monolog, I don't see anything we can do on our end here. Closing this for now.
I just tested Monolog 3.8 and 3.0, and it works like a charm.
It seems some wrappers in Laravel or other libraries are affecting the logging mechanism.