PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Utils / Logger.php

Logger.php in MultiSafepay plugin for WooCommerce trunk, at src/Utils/Logger.php

141 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Utils;
4
5 use WC_Log_Handler_File;
6 use WC_Logger_Interface;
7
8 /**
9 * Class Logger
10 */
11 class Logger {
12
13 /**
14 * @var WC_Logger_Interface
15 */
16 private $logger;
17
18 /**
19 * @param WC_Logger_Interface|null $logger
20 */
21 public function __construct( ?WC_Logger_Interface $logger = null ) {
22 $this->logger = $logger ?? wc_get_logger();
23 }
24
25 /**
26 * Log method for emergency level
27 * System is unusable.
28 * Example:
29 *
30 * @param string $message
31 */
32 public function log_emergency( string $message ) {
33 $this->logger->log( 'emergency', $message, array( 'source' => 'multisafepay' ) );
34 }
35
36 /**
37 * Log method for alert level
38 * Action must be taken immediately.
39 * Example: Entire website down, database unavailable, etc.
40 *
41 * @param string $message
42 */
43 public function log_alert( string $message ) {
44 $this->logger->log( 'alert', $message, array( 'source' => 'multisafepay' ) );
45 }
46
47 /**
48 * Log method for critical level
49 * Critical conditions.
50 * Example: Unexpected exceptions.
51 *
52 * @param string $message
53 */
54 public function log_critical( string $message ) {
55 $this->logger->log( 'critical', $message, array( 'source' => 'multisafepay' ) );
56 }
57
58 /**
59 * Log method for error level
60 * Error conditions
61 * Example: Set to shipped or invoiced an order, which is on initialized status
62 *
63 * @param string $message
64 */
65 public function log_error( string $message ) {
66 $this->logger->log( 'error', $message, array( 'source' => 'multisafepay' ) );
67 }
68
69 /**
70 * Log method for warning level
71 * Exceptional occurrences that are not errors because do not lead to a complete failure of the application.
72 * Example: Entire website down, database unavailable, etc.
73 *
74 * @param string $message
75 */
76 public function log_warning( string $message ) {
77 $this->logger->log( 'warning', $message, array( 'source' => 'multisafepay' ) );
78 }
79
80 /**
81 * Log method for notice level
82 * Normal but significant events.
83 * Example: A notification has been processed using a payment method different than the one registered when the order was created.
84 *
85 * @param string $message
86 */
87 public function log_notice( string $message ) {
88 $this->logger->log( 'notice', $message, array( 'source' => 'multisafepay' ) );
89 }
90
91 /**
92 * Log method for info level
93 * Interesting events.
94 * Example: The payment link of a transaction
95 *
96 * @param string $message
97 */
98 public function log_info( string $message ) {
99 if ( get_option( 'multisafepay_debugmode', false ) ) {
100 $this->logger->log( 'info', $message, array( 'source' => 'multisafepay' ) );
101 }
102 }
103
104 /**
105 * Log method for debug level
106 * Detailed debug information: Denotes specific and detailed information of every action.
107 * Example: The trace of every action registered in the system.
108 *
109 * @param string $message
110 */
111 public function log_debug( string $message ) {
112 if ( get_option( 'multisafepay_debugmode', false ) ) {
113 $this->logger->log( 'debug', $message, array( 'source' => 'multisafepay' ) );
114 }
115 }
116
117 /**
118 * Return an array of logs filenames
119 *
120 * @return array
121 */
122 private function get_logs(): array {
123 return WC_Log_Handler_File::get_log_files();
124 }
125
126 /**
127 * Return an array of logs that belongs to MultiSafepay
128 *
129 * @return array
130 */
131 public function get_multisafepay_logs(): array {
132 $logs = $this->get_logs();
133 foreach ( $logs as $key => $log ) {
134 if ( strpos( $log, 'multisafepay' ) === false ) {
135 unset( $logs[ $key ] );
136 }
137 }
138 return $logs;
139 }
140 }
141