1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!defined('ABSPATH')) { |
4
|
|
|
exit; // Exit if accessed directly |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class WCPagantisLogger |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public static $logger; |
12
|
|
|
const WC_LOG_FILENAME = 'pagantis-wc'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Utilize WC logger class |
16
|
|
|
* |
17
|
|
|
* @param $message |
18
|
|
|
* @param null $start_time |
|
|
|
|
19
|
|
|
* @param null $end_time |
|
|
|
|
20
|
|
|
* @since 8.6.7 |
21
|
|
|
*/ |
22
|
|
|
public static function writeLog($message, $start_time = null, $end_time = null) |
23
|
|
|
{ |
24
|
|
|
if (! class_exists('WC_Logger')) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (apply_filters('wc_stripe_logging', true, $message)) { |
|
|
|
|
29
|
|
|
if (empty(self::$logger)) { |
30
|
|
|
self::$logger = wc_get_logger(); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$settings = get_option('woocommerce_stripe_settings'); |
|
|
|
|
34
|
|
|
|
35
|
|
|
if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (! is_null($start_time)) { |
|
|
|
|
40
|
|
|
$formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
|
|
|
|
41
|
|
|
$end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
|
|
|
|
42
|
|
|
$formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
43
|
|
|
$elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
44
|
|
|
|
45
|
|
|
$log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
46
|
|
|
$log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
47
|
|
|
$log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
48
|
|
|
} else { |
49
|
|
|
$log_entry = "\n" . '====Pagantis Version: ' . PAGANTIS_VERSION . '====' . "\n"; |
50
|
|
|
$log_entry .= '====Start Log====' . "\n" . $message . "\n" . '====End Log====' . "\n\n"; |
51
|
|
|
} |
52
|
|
|
if (defined('WP_DEBUG') && WP_DEBUG) { |
|
|
|
|
53
|
|
|
error_log($log_entry); |
54
|
|
|
} |
55
|
|
|
print_r($log_entry); |
56
|
|
|
self::$logger->debug($log_entry, array( 'source' => self::WC_LOG_FILENAME )); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|