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 :)
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!");
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With