PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.6
YayMail – WooCommerce Email Customizer v4.4.6
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
← All changes | src/Utils/Logger.php +17 -3 4.4.4 → 4.4.6 View file →
@@ -9,14 +9,16 @@
9 9 private $log_directory;
10 10 private $wp_filesystem;
11 11 private $max_log_files;
12 12
13 + private $ready = false;
14 +
13 15 /**
14 16 * Constructor for the Logger class.
15 17 *
16 - * Initializes the logger with a specified log directory, prefix for log entries,
17 - * and the maximum number of log files to keep. Ensures the log directory exists and
18 - * performs cleanup of old log files.
18 + * Only records the log directory and retention limit. Filesystem setup (WP_Filesystem,
19 + * mkdir, old-log cleanup) is deferred to the first log() call because Logger instances
20 + * are created on every request by classes that rarely log.
19 21 */
20 22 public function __construct( $log_directory = null, $max_log_files = 30 ) {
21 23 if ( ! $log_directory ) {
22 24 $log_directory = WP_CONTENT_DIR . '/yaymail-logs';
@@ -22,8 +24,18 @@
22 24 $log_directory = WP_CONTENT_DIR . '/yaymail-logs';
23 25 }
24 26 $this->log_directory = $log_directory;
25 27 $this->max_log_files = $max_log_files;
28 + }
29 +
30 + /**
31 + * Initializes the filesystem, ensures the log directory exists and prunes old logs. Runs once.
32 + */
33 + private function ensure_ready() {
34 + if ( $this->ready ) {
35 + return;
36 + }
37 + $this->ready = true;
26 38 $this->initialize_filesystem();
27 39
28 40 // Ensure the log directory exists (only if filesystem is available)
29 41 if ( $this->wp_filesystem && ! $this->wp_filesystem->is_dir( $this->log_directory ) ) {
@@ -91,8 +103,10 @@
91 103 }
92 104 }
93 105
94 106 public function log( $message ) {
107 + $this->ensure_ready();
108 +
95 109 // Return early if filesystem is not available
96 110 if ( ! $this->wp_filesystem ) {
97 111 return;
98 112 }