PHP Program run error log information save format problem

Source: Internet
Author: User
Tags log log
I want to add log monitoring to some of the running points in my program and use them directly file_put_contentsCan be executed to a point where the information is recorded, but it cannot save the output of the program format, write the saved data is the form of text, can not be saved such as in the browser directly printed array format or jsonFormat it! That's how I write it.

file_put_contents("../fileLog/{$time}.log", $error);

It is desirable to be able to save the full data format and to accumulate error messages. For you.

Reply content:

I want to in my own program some of the operating point of the log monitoring, direct use file_put_contents can be executed to a certain point of the place to record the information, but cannot save the output of the program format, write the saved data is the form of text, can not be saved such as in the browser directly printed array format or jsonFormat It! That's how I write it.

file_put_contents("../fileLog/{$time}.log", $error);

It is desirable to be able to save the full data format and to accumulate error messages. For you.

You can use var_export() the output of your error message. If you want to accumulate records file_put_contents have corresponding parameters, set up can also support the accumulation of line, and then give you the error message system time, can better view the error time and error messages. For example

file_put_contents("../fileLog/{$time}.log", var_export($error, true) . "【Time:" . date("Y-m-d H:i:s") . '】' . PHP_EOL, FILE_APPEND);

However, the addition of this time will also cause your log log file error data information becomes more and more large. Pay attention to clean up in time. Hope to help you

Search the Seaslog. This log extension
To meet your needs.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.