Ever wondered to have a customised log function to get array or text as input and add it to file with the exact date and time?
guess what? here is the function, you can add it to your config file( or in WordPress add it to functions.php) and call it anywhere in your code to log the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <?php function riksi_log($input_msg){ $log_text=""; //get the event occur date time,when it will happened $logData['log_datetime']='['.date('D Y-m-d h:i:s A').'] [client '.$_SERVER['REMOTE_ADDR'].']'; //if message is array type if(is_array($input_msg)){ //concatenate msg with datetime foreach($input_msg as $msg) $log_text.=$logData['log_datetime']." ".$msg."\r\n"; }else{ //concatenate msg with datetime $log_text.=$logData['log_datetime']." ".$input_msg."\r\n"; } //create file with current date name $logName='kobelog_'.date('Ymd').'.txt'; //open the file in append mode $fHandler=fopen($logName,'a+'); //write the info into the file fwrite($fHandler,$log_text); //close handler fclose($fHandler); } ?> |
its usefull if you want to test your code and see the content of the array, othe functions passed.
simply call the function like:
1 2 3 4 5 | riksi_log($input_msg) |