Merge branch 'pr/10689'

This commit is contained in:
Mike Jolley 2016-04-19 14:00:46 +01:00
commit fb8708dea6
1 changed files with 32 additions and 17 deletions

View File

@ -7,11 +7,11 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* Allows log files to be written to for debugging purposes
*
* @class WC_Logger
* @version 1.6.4
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @class WC_Logger
* @version 1.6.4
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
*/
class WC_Logger {
@ -30,7 +30,6 @@ class WC_Logger {
$this->_handles = array();
}
/**
* Destructor.
*/
@ -40,54 +39,70 @@ class WC_Logger {
}
}
/**
* Open log file for writing.
*
* @access private
* @param mixed $handle
*
* @param string $handle
* @param string $mode
*
* @return bool success
*/
private function open( $handle ) {
private function open( $handle, $mode = 'a' ) {
if ( isset( $this->_handles[ $handle ] ) ) {
return true;
}
if ( $this->_handles[ $handle ] = @fopen( wc_get_log_file_path( $handle ), 'a' ) ) {
if ( $this->_handles[ $handle ] = @fopen( wc_get_log_file_path( $handle ), $mode ) ) {
return true;
}
return false;
}
/**
* Add a log entry to chosen file.
*
* @param string $handle
* @param string $message
*
* @return bool
*/
public function add( $handle, $message ) {
$result = false;
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" );
$time = date_i18n( 'm-d-Y @ H:i:s -' ); // Grab Time
$result = fwrite( $this->_handles[ $handle ], $time . " " . $message . "\n" );
}
do_action( 'woocommerce_log_add', $handle, $message );
}
return false !== $result;
}
/**
* Clear entries from chosen file.
*
* @param mixed $handle
* @param string $handle
*
* @return bool
*/
public function clear( $handle ) {
if ( $this->open( $handle ) && is_resource( $this->_handles[ $handle ] ) ) {
@ftruncate( $this->_handles[ $handle ], 0 );
$result = false;
/**
* $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at the beginning of the file,
* and truncate the file to zero length.
*/
if ( $this->open( $handle, 'w' ) && is_resource( $this->_handles[ $handle ] ) ) {
$result = true;
}
do_action( 'woocommerce_log_clear', $handle );
return $result;
}
}