_handles = array(); } /** * Destructor. * * @access public * @return void */ public 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 ) { if ( isset( $this->_handles[ $handle ] ) ) { return true; } if ( $this->_handles[ $handle ] = @fopen( wc_get_log_file_path( $handle ), 'a' ) ) { return true; } return false; } /** * Add a log entry to chosen file. * * @access public * @param string $handle * @param string $message * @return void */ public function add( $handle, $message ) { if ( $this->open( $handle ) && is_resource( $this->_handles[ $handle ] ) ) { $time = date_i18n( 'm-d-Y @ H:i:s -' ); // Grab Time @fwrite( $this->_handles[ $handle ], $time . " " . $message . "\n" ); } do_action( 'woocommerce_log_add', $handle, $message ); } /** * Clear entries from chosen file. * * @access public * @param mixed $handle * @return void */ public function clear( $handle ) { if ( $this->open( $handle ) && is_resource( $this->_handles[ $handle ] ) ) { @ftruncate( $this->_handles[ $handle ], 0 ); } do_action( 'woocommerce_log_clear', $handle ); } }