1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<?php
class SwpmLog { private $error; private $warn; private $notice; private static $intance; private function __construct() { $this->error = array(); $this->warn = array(); $this->notice = array(); } public static function get_logger($context = ''){ $context = empty($context)? 'default': $context; if (!isset(self::$intance[$context])){ self::$intance[$context] = new SwpmLog(); } return self::$intance[$context]; } public function error($msg){ $this->error[] = $msg; } public function warn($msg){ $this->warn[] = $msg; } public function debug($msg){ $this->notice[] = $msg; } public function get($to_screen = false){ $msg = ''; foreach ($this->error as $error ){ $msg .= 'ERROR: ' . $error . ($to_screen?"<br/>":"\n"); } foreach($this->warn as $warn){ $msg .= 'WARN: ' . $warn . ($to_screen?"<br/>":"\n"); } foreach ($this->notice as $notice){ $msg = 'NOTICE: ' . $notice . ($to_screen?"<br/>":"\n"); } return $msg; } public static function writeall($path = ''){ if (empty($path)) {$path = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';} $fp = fopen($path, 'a'); $date = date("Y-m-d H:i:s"); fwrite($fp, strtoupper($date) . ":\n"); fwrite($fp, str_repeat('-=', (strlen($date)+1.0)/2.0) . "\n"); foreach (self::$intance as $context=>$intance){ fwrite($fp, strtoupper($context) . ":\n"); fwrite($fp, str_repeat('=', strlen($context)+1) . "\n"); fwrite($fp, $intance->get()); } fclose($fp); }
public static function log_simple_debug($message, $success, $end = false) { $settings = SwpmSettings::get_instance(); $debug_enabled = $settings->get_value('enable-debug'); if (empty($debug_enabled)) {//Debug is not enabled return; }
//Lets write to the log file $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';
// Timestamp $text = '[' . date('m/d/Y g:i A') . '] - ' . (($success) ? 'SUCCESS: ' : 'FAILURE: ') . $message . "\n"; if ($end) { $text .= "\n------------------------------------------------------------------\n\n"; } // Write to log $fp = fopen($debug_log_file_name, 'a'); fwrite($fp, $text); fclose($fp); // close file } public static function log_array_data_to_debug($array_to_write, $success, $end = false) { $settings = SwpmSettings::get_instance(); $debug_enabled = $settings->get_value('enable-debug'); if (empty($debug_enabled)) {//Debug is not enabled return; }
//Lets write to the log file $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt';
// Timestamp $text = '[' . date('m/d/Y g:i A') . '] - ' . (($success) ? 'SUCCESS: ' : 'FAILURE: ') . "\n"; ob_start(); print_r($array_to_write); $var = ob_get_contents(); ob_end_clean(); $text .= $var; if ($end) { $text .= "\n------------------------------------------------------------------\n\n"; } // Write to log $fp = fopen($debug_log_file_name, 'a'); fwrite($fp, $text); fclose($fp); // close file } public static function log_auth_debug($message, $success, $end = false) { $settings = SwpmSettings::get_instance(); $debug_enabled = $settings->get_value('enable-debug'); if (empty($debug_enabled)) {//Debug is not enabled return; }
//Lets write to the log file $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log-auth.txt';
// Timestamp $text = '[' . date('m/d/Y g:i A') . '] - ' . (($success) ? 'SUCCESS: ' : 'FAILURE: ') . $message . "\n"; if ($end) { $text .= "\n------------------------------------------------------------------\n\n"; } // Write to log $fp = fopen($debug_log_file_name, 'a'); fwrite($fp, $text); fclose($fp); // close file } public static function reset_swmp_log_files() { $log_reset = true; $logfile_list = array( SIMPLE_WP_MEMBERSHIP_PATH . '/log.txt', SIMPLE_WP_MEMBERSHIP_PATH . '/log-auth.txt', );
foreach ($logfile_list as $logfile) { if (empty($logfile)) { continue; }
$text = '[' . date('m/d/Y g:i A') . '] - SUCCESS: Log file reset'; $text .= "\n------------------------------------------------------------------\n\n"; $fp = fopen($logfile, 'w'); if ($fp != FALSE) { @fwrite($fp, $text); @fclose($fp); } else { $log_reset = false; } } return $log_reset; }
}
|