79525837

Date: 2025-03-21 15:07:39
Score: 2
Natty:
Report link

Oh, thanx to @JON and @Manish !

I'm using a slightly improved version that checks the data type and outputs it in a convenient way if it's an object or an array.

//PHP log helper - root/log folder (v0.57)
function wr_log($log_msg)
{
    $log_path = $_SERVER['DOCUMENT_ROOT']."/log";

    if (!file_exists($log_path))
    {
        //create dir for logs
        mkdir($log_path, 0777, true);
    }

    $log_filename = $log_path.'/log_' . date('Y-m-d') . '.log'; //date('d-M-Y')

    if( is_array($log_msg) || is_object($log_msg) ) $log = print_r($log_msg, true);
    else $log = $log_msg;

    file_put_contents($log_filename, $log ."\n", FILE_APPEND);
}
Reasons:
  • Blacklisted phrase (1): thanx
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @JON
  • User mentioned (0): @Manish
  • Low reputation (1):
Posted by: Romaster590