abstracts
3 months ago
admin
3 months ago
frontend
1 month ago
integrations
1 month ago
v3
3 months ago
vendor
6 days ago
views
8 months ago
class-simplesalestax.php
6 days ago
class-sst-addresses.php
1 month ago
class-sst-ajax.php
3 months ago
class-sst-assets.php
6 months ago
class-sst-blocks-integration.php
1 month ago
class-sst-blocks.php
1 year ago
class-sst-certificates.php
6 days ago
class-sst-install.php
6 months ago
class-sst-logger.php
5 months ago
class-sst-marketplaces.php
6 months ago
class-sst-order-controller.php
3 months ago
class-sst-order.php
1 month ago
class-sst-origin-address.php
8 months ago
class-sst-product.php
3 months ago
class-sst-rate-limit.php
5 months ago
class-sst-settings.php
3 months ago
class-sst-shipping.php
3 years ago
class-sst-taxcloud-v3-api.php
3 months ago
class-sst-taxcloud-v3.php
3 months ago
class-sst-tic.php
2 years ago
class-sst-updater.php
3 years ago
sst-compatibility-functions.php
4 months ago
sst-functions.php
6 days ago
sst-message-functions.php
3 years ago
sst-update-functions.php
11 months ago
class-sst-logger.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly. |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Logger. |
| 9 | * |
| 10 | * Used for logging error messages. |
| 11 | * |
| 12 | * @author Simple Sales Tax |
| 13 | * @package SST |
| 14 | * @since 5.0 |
| 15 | */ |
| 16 | class SST_Logger { |
| 17 | |
| 18 | /** |
| 19 | * Log handle. |
| 20 | * |
| 21 | * @var string |
| 22 | * @since 5.0 |
| 23 | */ |
| 24 | protected static $handle = 'wootax'; |
| 25 | |
| 26 | /** |
| 27 | * Logger instance. |
| 28 | * |
| 29 | * @var WC_Logger |
| 30 | * @since 5.0 |
| 31 | */ |
| 32 | protected static $logger = null; |
| 33 | |
| 34 | /** |
| 35 | * Initialize the logger instance. |
| 36 | * |
| 37 | * @since 5.0 |
| 38 | */ |
| 39 | public static function init() { |
| 40 | if ( 'yes' === SST_Settings::get( 'log_requests' ) ) { |
| 41 | /** |
| 42 | * Create a new log file every day. |
| 43 | */ |
| 44 | self::$handle = self::$handle . '-' . gmdate( 'Y-m-d' ); |
| 45 | self::$logger = function_exists( 'wc_get_logger' ) ? wc_get_logger() : new WC_Logger(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get log file path. |
| 51 | * |
| 52 | * @return string |
| 53 | * @since 5.0 |
| 54 | */ |
| 55 | public static function get_log_path() { |
| 56 | return wc_get_log_file_path( self::$handle ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Add a log entry. |
| 61 | * |
| 62 | * @param string $message Log message. |
| 63 | * |
| 64 | * @since 5.0 |
| 65 | */ |
| 66 | public static function add( $message, $context = array() ) { |
| 67 | if ( ! is_null( self::$logger ) ) { |
| 68 | self::$logger->notice( $message, array( |
| 69 | 'source' => self::$handle, |
| 70 | '_context' => (array) $context |
| 71 | ) |
| 72 | ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * Log a debug message. |
| 79 | * |
| 80 | * @param string $message Log message. |
| 81 | * @param array $context Log context. |
| 82 | * |
| 83 | * @since 8.3.4 |
| 84 | */ |
| 85 | public static function debug( $message, $context = array() ) { |
| 86 | if ( ! is_null( self::$logger ) ) { |
| 87 | self::$logger->debug( $message, array( |
| 88 | 'source' => self::$handle, |
| 89 | '_context' => (array) $context |
| 90 | ) |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Log an order message. |
| 97 | * |
| 98 | * @param string $message Log message. |
| 99 | * @param array $context Log context. |
| 100 | * |
| 101 | * @since 8.3.4 |
| 102 | */ |
| 103 | public static function order_log( $message, $order_id, $context = array() ) { |
| 104 | if ( ! is_null( self::$logger ) ) { |
| 105 | self::$logger->debug( $message, array( |
| 106 | 'source' => 'wootax-order-' . $order_id, |
| 107 | '_context' => (array) $context |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Log an error message. |
| 115 | * |
| 116 | * @param string $message Log message. |
| 117 | * @param array $context Log context. |
| 118 | * |
| 119 | * @since 8.4.2 |
| 120 | */ |
| 121 | public static function error( $message, $context = array() ) { |
| 122 | if ( ! is_null( self::$logger ) ) { |
| 123 | self::$logger->error( $message, array( |
| 124 | 'source' => self::$handle, |
| 125 | '_context' => (array) $context |
| 126 | ) |
| 127 | ); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | } |
| 132 | |
| 133 | SST_Logger::init(); |
| 134 |