Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Instead of doing ECHO's to debug variable values, how to send the value to a file?

Tags:

php

logging

I need to debug an Application, but the ECHO $variable it is not working.

How can I send the value of the variable to a log file?

Give me some clues.

Best Regards,

like image 543
Joel Avatar asked Dec 17 '22 15:12

Joel


1 Answers

trigger_error in combination with error_reporting allows you to easily log what you want on development servers, without worrying about the load on your production servers.

It adds more information than error_log:

trigger_error('foo');

results in

[Fri Apr 08 14:28:08 2011] [error] [client 192.168.0.13] PHP Notice:  foo in /data/sites/kai/public_html/foo.php on line 3

whereas error_log('foo'); results in

[Fri Apr 08 14:28:08 2011] [error] [client 192.168.0.13] foo
like image 134
Ken Avatar answered May 07 '23 04:05

Ken