1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
4
|
|
|
exit; // Exit if accessed directly |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Log helper for debugging |
9
|
|
|
*/ |
10
|
|
|
class pagantisLogger { |
11
|
|
|
|
12
|
|
|
public static $logger; |
13
|
|
|
const PG_LOG_FILENAME = 'pagantis-woocommerce-gateway'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Utilize WC logger class |
17
|
|
|
* |
18
|
|
|
* @param $message |
19
|
|
|
* @param null $start_time |
|
|
|
|
20
|
|
|
* @param null $end_time |
|
|
|
|
21
|
|
|
* |
22
|
|
|
* @version 1.0.0 |
23
|
|
|
* @since 8.6.9 |
24
|
|
|
*/ |
25
|
|
|
public static function log( $message, $start_time = null, $end_time = null ) { |
26
|
|
|
if ( ! class_exists( 'WC_Logger' ) ) { |
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if ( empty( self::$logger ) ) { |
31
|
|
|
if (version_compare( WC_VERSION, 3.0, '<' )) { |
|
|
|
|
32
|
|
|
self::$logger = new WC_Logger(); |
|
|
|
|
33
|
|
|
} else { |
34
|
|
|
self::$logger = wc_get_logger(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
if (!defined( 'WP_DEBUG' )) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ( ! is_null( $start_time ) ) { |
|
|
|
|
43
|
|
|
|
44
|
|
|
$formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
|
|
|
|
45
|
|
|
$end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
|
|
|
|
46
|
|
|
$formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
47
|
|
|
$elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
48
|
|
|
|
49
|
|
|
$log_entry = "\n" . '====Pagantis Version: ' . PG_VERSION . '====' . "\n"; |
50
|
|
|
$log_entry .= '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
51
|
|
|
$log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
52
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
$log_entry = "\n" . '====Pagantis Version: ' . PG_VERSION . '====' . "\n"; |
55
|
|
|
$log_entry .= '====Start Log====' . "\n" . $message . "\n" . '====End Log====' . "\n\n"; |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (version_compare( WC_VERSION, 3.0, '<' )) { |
60
|
|
|
self::$logger->add( self::PG_LOG_FILENAME, $log_entry ); |
61
|
|
|
} else { |
62
|
|
|
self::$logger->debug( $log_entry, array( 'source' => self::PG_LOG_FILENAME ) ); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|