/
class-wc-logger.php
104 lines (88 loc) · 1.79 KB
/
class-wc-logger.php
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
<?php
/**
* Allows log files to be written to for debugging purposes.
*
* @class WC_Logger
* @version 1.6.4
* @package WooCommerce/Classes
* @author WooThemes
*/
class WC_Logger {
/**
* @var array Stores open file handles.
* @access private
*/
private $handles;
/**
* Constructor for the logger.
*
* @access public
* @return void
*/
function __construct() {
$this->handles = array();
}
/**
* Destructor.
*
* @access public
* @return void
*/
function __destruct() {
foreach ($this->handles as $handle)
fclose( $handle );
}
/**
* Open log file for writing.
*
* @access private
* @param mixed $handle
* @return bool success
*/
private function open( $handle ) {
global $woocommerce;
if ( isset( $this->handles[$handle] ) )
return true;
if ( $this->handles[$handle] = @fopen( $woocommerce->plugin_path() . '/logs/' . $handle . '.txt', 'a' ) )
return true;
return false;
}
/**
* Add a log entry to chosen file.
*
* @access public
* @param mixed $handle
* @param mixed $message
* @return void
*/
public function add( $handle, $message ) {
if ( $this->open( $handle ) ) {
$time = date_i18n( 'm-d-Y @ H:i:s -' ); //Grab Time
fwrite( $this->handles[$handle], $time . " " . $message . "\n" );
}
}
/**
* Clear entrys from chosen file.
*
* @access public
* @param mixed $handle
* @return void
*/
public function clear( $handle ) {
if ( $this->open( $handle ) )
ftruncate( $this->handles[$handle], 0 );
}
}
/**
* woocommerce_logger class.
*
* @extends WC_Logger
* @deprecated 1.4
* @package WooCommerce/Classes
*/
class woocommerce_logger extends WC_Logger {
public function __construct() {
_deprecated_function( 'woocommerce_logger', '1.4', 'WC_Logger()' );
parent::__construct();
}
}