John Davidson

Laravel/PHP logging to console/terminal without concerning about types etc

0 comments
Message:


Is there sth. similar like console.log() from javascript in php?


The problem which i have in laravel for e.x.


error_log($request);

is not working, cause $request is not a string etc.


https://laravel.com/docs/8.x/logging#introduction


For me this seems too complicated for what i want to archive, honsetly i don't understand it at all.
What is the easiest way to log in laravel/php without thinking about types etc.


Is there maybe a library which i can install and log to terminal without a second though and tedious setup work? maybe a VSCode extension?



My Answer:
One simple way to log to the console/terminal in Laravel/PHP without worrying about types is to use the `dump()` function. This function will output the variable to the console in a human-readable format.

For example, you can use `dump($request);` to log the contents of the `$request` variable to the console.

Another option is to use the `dd()` function, which stands for "dump and die". This function will output the variable to the console and then stop the execution of the script.

You can also use `var_dump()` or `print_r()` functions for logging to the console in PHP.

If you prefer a more structured logging solution, you can consider using a logging library like Monolog, which is included in Laravel by default. You can configure Monolog to log to the console/terminal by adding a handler for the `StreamHandler` in your `config/logging.php` file.

Overall, using `dump()`, `dd()`, `var_dump()`, or `print_r()` functions should be the easiest way to log to the console in Laravel/PHP without worrying about types.

Rate this post

4 of 5 based on 9636 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us