Cara menggunakan add error log php
Saat membangun sebuah website, seringkali web developer menjumpai error. Cara yang paling baik adalah memulai debugging atau mencari sumber masalah dengan membaca error log. Pada tutorial kali ini kita akan belajar dua hal, memunculkan error langsung di web (display error) dan mengaktifkan error log di cPanel melalui MultiPHP INI editor, berikut langkahnya:
Setelah menyelesaikan langkah diatas, anda bisa melihat file error dengan nama error_log di direktori utama (home directory). Namun perlu diperhatikan bahwa setelah selesai memperbaiki error, ada baiknya opsi ini dikembalikan lagi menjadi Off, karena seiring waktu ukuran error_log akan terus membesar. Untuk menonaktifkannya Anda hanya perlu mengganti value log_errors ke Off. Selamat berburu error! Bermanfaatkah Artikel Ini? Klik bintang 5 untuk rating! Rata rata rating 5 / 5. Jumlah rate 1 No votes so far! Be the first to rate this post. We are sorry that this post was not useful for you! Let us improve this post! Tell us how we can improve this post? View Discussion Improve Article Save Article View Discussion Improve Article Save Article In PHP, errors and warnings can be logged into a file by using a php script and changing configuration of php.ini file. Two such approaches are mentioned below: Approach 1: The error_log() function can be used to send error messages to a given file. First argument to the function is the error message to be sent. Second argument tells where to send/log the error message. In this case, second argument is set to 3, used to redirect error message to a file. Third argument is used to specify the file path of the error logging file. Below is the implementation of the above approach:
Output: [20-Dec-2018 17:32:00 UTC] This is an error message! Approach 2:
Below is the implementation of the above approach:
Output: [20-Dec-2018 17:30:35 UTC] This is an error message! Similar Approach: Following lines can also be added directly to php.ini to make the configuration changes permanent for every php script that logs errors and warnings. log_errors = on error_log = ./errors.log Note:: This approach is not highly reliable as compared to other approaches. Its better to use approach 1 as it gives flexibility of choosing different files for logging at same time without changing configuration of php.ini file. |