PHP program running error log information saving format problem

WBOY
Release: 2016-08-04 09:20:13
Original
1199 people have browsed it

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>
Copy after login
Copy after login

Hope to be able to save the complete data format, and it is best to accumulate error information. Please give me some advice

Reply content:

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>
Copy after login
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!