<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

if (!function_exists('custom_log_message')) {

    function custom_log_message($level, $message, $file_pre_name = 'custom') {
        // Get the CodeIgniter instance
        $CI = & get_instance();
        // Define the log directory and file name
        $log_path = APPPATH . 'logs/';
        $date = date('Y-m-d');
        $time = date('H-i'); // Use '-' instead of ':' for file name
        $log_file = "log-" . $file_pre_name . "_" . $date . "_" . $time . ".php";
        // Create the log directory if it doesn't exist
        if (!file_exists($log_path)) {
            mkdir($log_path, 0755, true);
        }
        // Prepare the log entry
        $log_entry = date('Y-m-d H:i:s') . " --> " . $level . ": " . $message . "\n";
        // Write the log entry to the file
        file_put_contents($log_path . $log_file, $log_entry, FILE_APPEND);
    }

}
