<?php
/**
 * Credorax Payments For WooCommerce
 * https://www.credorax.com/
 *
 * @category Credorax
 * @package  WC_Credorax
 * @author   Girit-Interactive (https://www.girit-tech.com/)
 */

if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

/**
 * WC_Credorax_Model_Logger
 */
class WC_Credorax_Model_Logger
{
    const WC_LOG_FILENAME = 'woocommerce-gateway-credorax';

    public static $logger;

    public static function log($message, $type = "debug", $data = [], $prefix = '[Credorax] ')
    {
        if (! class_exists('WC_Logger')) {
            return;
        }

        if (empty(self::$logger)) {
            //if (version_compare(WC_VERSION, '3.0', '<')) {
            //    self::$logger = new WC_Logger();
            //} else {
            self::$logger = wc_get_logger();
            //}
        }

        if ($type !== 'debug' || WC_Credorax_Model_Config::isDebugEnabled()) {
            $message = $prefix . date('Y-m-d H:i:s') . "\nType: " . $type . "\nMessage: " . print_r($message, true) . "\nData: " . print_r($data, true);

            //if (version_compare(WC_VERSION, '3.0', '<')) {
            //    self::$logger->add(self::WC_LOG_FILENAME, $message);
            //} else {
            self::$logger->log($type, $message, array( 'source' => self::WC_LOG_FILENAME ));
            //}
        }
    }
}
