How to debug or log some special variables in Craft CMS? (Especially in a controller)
You could use for example the dd() method with the craft3-dumper package.
You can also use the debug toolbar.
You could also use Sentry to get a nice overview about your errors with the craft sentry package.
Or you could use xdebug. Or or or ... :)

So there are severals ways to debug something.