Home > Article > Backend Development > PHP program running error log information saving format problem
I want to add log monitoring at certain running points in my program. Directly using file_put_contents
can record the information when the execution reaches a certain program point, but the output program format cannot be saved and written. The saved data is all in the form of text. Can it be saved in array format or json
format that can be printed directly in the browser? This is how I write
<code>file_put_contents("../fileLog/{$time}.log", $error);</code>
Hope to be able to save the complete data format, and it is best to accumulate error information. Please give me some advice
I want to add log monitoring at certain running points in my program. Directly using file_put_contents
can record the information when the execution reaches a certain program point, but the output program format cannot be saved and written. The saved data is all in the form of text. Can it be saved in array format or json
format that can be printed directly in the browser? This is how I write
<code>file_put_contents("../fileLog/{$time}.log", $error);</code>
Hope to be able to save the complete data format, and it is best to accumulate error information. Please give me some advice
You can use var_export()
to output your error message. If you want to accumulate records, file_put_contents
has corresponding parameters. You can set it and support cumulative line breaks. Then add the system time to your error message to better view the error time and error message. For example
<code>file_put_contents("../fileLog/{$time}.log", var_export($error, true) . "【Time:" . date("Y-m-d H:i:s") . '】' . PHP_EOL, FILE_APPEND);</code>
However, the accumulation of these errors will also cause your log file error data to become larger and larger. Pay attention to clean up in time. Hope it helps you
Search for SeasLog, this log extension
can meet your needs