Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i save logs in php

Tags:

php

How do i save logs in PHP? Is there any "magical" function available in php for doing so, or any library? Or should i have to fopen file everytime and dump in it? I want to save my logs in text file.

Thanks in advance :)

like image 235
TCM Avatar asked Jul 06 '10 14:07

TCM


People also ask

How do I save a PHP log?

The default file type is ". For example: //changing file type, can be put after class include Logg::$fileType = ". txt"; //logging some example messages Logg::addInfo("Log message now in . txt file"); Logg::addWarn("Everything will be saved to this file from now on!");

How can I get PHP log?

Look for the entry Configuration File (php. Find the Error handling and logging section of the php. ini file. Make sure that both display_errors = On, display_startup_errors = On and log_errors = On are present and uncommented. Check the value of error_log - this tells you the location of the file errors are logged to.

Where are PHP logs in Linux?

If the syslog is used, then all PHP errors will be sent directly to the default system log file—in Linux, this is typically /var/log/syslog.


1 Answers

If you do not want to use an own implementation or just do fopen-stuff you cyn use the built in function error_log('string to log'); . This will write the desired string into the error log of your server software.

like image 197
Thariama Avatar answered Sep 21 '22 17:09

Thariama