PHP Add log file

Source: Internet
Author: User

Record it.

Sometimes when writing test code, not used to directly output feedback on the screen, then you can configure the log file, the output needs to append to the log file, it is very convenient.

PHP comes with a log system, you can refer to the online blog configuration.

I would like to say that if you have more than one application under the Web server, all append log to a file, then, emmm ...

Workaround:
Create a dedicated log folder in each app, and append the content output to the file in the application. This method is very easy to think of. relatively simple.

First, for example, my application name is WX, so I built a logs folder inside, with two log files. After creating the file, it is best to use the chmod 777 Error.log command to elevate the file read and write permissions. Of course, it doesn't necessarily raise to 777. Also, the folder directly named logs in the production environment is not good, can be appropriately complicated naming, not easy to be guessed out.

Once the log file has been created, it is ready to be written in our code.

    function successlog ($log)    {        $filegetcwd(). " /logs/success.log ";         Var_dump ($file);         $content Date  Time $log ;         file_put_contents ($file$content, file_append);    }

$file to get the file, the absolute path is used here, and the relative path does not get the file. To enhance the portability of your application, you can use GETCWD to get the current path and assemble the required strings.

It is recommended that the current time be output when the log is output for easy viewing. Append to the log file, you can write "\ n" in the string to break the line.

PHP Add log file

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.