Replace log `tag` with log `source`
This commit is contained in:
parent
03889f77cc
commit
e4d5886427
|
@ -72,7 +72,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
'timestamp' => __( 'Timestamp', 'woocommerce' ),
|
'timestamp' => __( 'Timestamp', 'woocommerce' ),
|
||||||
'level' => __( 'Level', 'woocommerce' ),
|
'level' => __( 'Level', 'woocommerce' ),
|
||||||
'message' => __( 'Message', 'woocommerce' ),
|
'message' => __( 'Message', 'woocommerce' ),
|
||||||
'tag' => __( 'Tag', 'woocommerce' ),
|
'source' => __( 'Source', 'woocommerce' ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +133,13 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag column.
|
* Source column.
|
||||||
*
|
*
|
||||||
* @param array $log
|
* @param array $log
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_tag( $log ) {
|
public function column_source( $log ) {
|
||||||
return esc_html( $log['tag'] );
|
return esc_html( $log['source'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,7 +162,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
return array(
|
return array(
|
||||||
'timestamp' => array( 'timestamp', true ),
|
'timestamp' => array( 'timestamp', true ),
|
||||||
'level' => array( 'level', true ),
|
'level' => array( 'level', true ),
|
||||||
'tag' => array( 'tag', true ),
|
'source' => array( 'source', true ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
|
|
||||||
$search = '';
|
$search = '';
|
||||||
if ( ! empty( $_REQUEST['s'] ) ) {
|
if ( ! empty( $_REQUEST['s'] ) ) {
|
||||||
$search = "AND tag LIKE '%" . esc_sql( $wpdb->esc_like( wc_clean( $_REQUEST['s'] ) ) ) . "%' ";
|
$search = "AND source LIKE '%" . esc_sql( $wpdb->esc_like( wc_clean( $_REQUEST['s'] ) ) ) . "%' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $_REQUEST['orderby'] ) ) {
|
if ( ! empty( $_REQUEST['orderby'] ) ) {
|
||||||
|
@ -205,7 +205,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
|
|
||||||
// Intentional cascade, these are valid values.
|
// Intentional cascade, these are valid values.
|
||||||
case 'timestamp':
|
case 'timestamp':
|
||||||
case 'tag':
|
case 'source':
|
||||||
case 'level':
|
case 'level':
|
||||||
$order_by = $_REQUEST['orderby'];
|
$order_by = $_REQUEST['orderby'];
|
||||||
break;
|
break;
|
||||||
|
@ -226,7 +226,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items = $wpdb->get_results(
|
$this->items = $wpdb->get_results(
|
||||||
"SELECT log_id, timestamp, level, message, tag
|
"SELECT log_id, timestamp, level, message, source
|
||||||
FROM {$wpdb->prefix}woocommerce_log
|
FROM {$wpdb->prefix}woocommerce_log
|
||||||
WHERE 1 = 1 {$level_filter} {$search}
|
WHERE 1 = 1 {$level_filter} {$search}
|
||||||
ORDER BY {$order_by} {$order_order} " .
|
ORDER BY {$order_by} {$order_order} " .
|
||||||
|
|
|
@ -41,7 +41,7 @@ class WC_Background_Updater extends WP_Background_Process {
|
||||||
if ( is_wp_error( $dispatched ) ) {
|
if ( is_wp_error( $dispatched ) ) {
|
||||||
$logger->error(
|
$logger->error(
|
||||||
sprintf( 'Unable to dispatch WooCommerce updater: %s', $dispatched->get_error_message() ),
|
sprintf( 'Unable to dispatch WooCommerce updater: %s', $dispatched->get_error_message() ),
|
||||||
array( 'tag' => 'wc_db_updates' )
|
array( 'source' => 'wc_db_updates' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,11 +105,11 @@ class WC_Background_Updater extends WP_Background_Process {
|
||||||
include_once( dirname( __FILE__ ) . '/wc-update-functions.php' );
|
include_once( dirname( __FILE__ ) . '/wc-update-functions.php' );
|
||||||
|
|
||||||
if ( is_callable( $callback ) ) {
|
if ( is_callable( $callback ) ) {
|
||||||
$logger->info( sprintf( 'Running %s callback', $callback ), array( 'tag' => 'wc_db_updates' ) );
|
$logger->info( sprintf( 'Running %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||||
call_user_func( $callback );
|
call_user_func( $callback );
|
||||||
$logger->info( sprintf( 'Finished %s callback', $callback ), array( 'tag' => 'wc_db_updates' ) );
|
$logger->info( sprintf( 'Finished %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||||
} else {
|
} else {
|
||||||
$logger->notice( sprintf( 'Could not find %s callback', $callback ), array( 'tag' => 'wc_db_updates' ) );
|
$logger->notice( sprintf( 'Could not find %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -123,7 +123,7 @@ class WC_Background_Updater extends WP_Background_Process {
|
||||||
*/
|
*/
|
||||||
protected function complete() {
|
protected function complete() {
|
||||||
$logger = wc_get_logger();
|
$logger = wc_get_logger();
|
||||||
$logger->info( 'Data update complete', array( 'tag' => 'wc_db_updates' ) );
|
$logger->info( 'Data update complete', array( 'source' => 'wc_db_updates' ) );
|
||||||
WC_Install::update_db_version();
|
WC_Install::update_db_version();
|
||||||
parent::complete();
|
parent::complete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1173,7 +1173,7 @@ class WC_Geo_IP {
|
||||||
if ( empty( self::$log ) ) {
|
if ( empty( self::$log ) ) {
|
||||||
self::$log = wc_get_logger();
|
self::$log = wc_get_logger();
|
||||||
}
|
}
|
||||||
self::$log->log( $level, $message, array( 'tag' => 'geoip' ) );
|
self::$log->log( $level, $message, array( 'source' => 'geoip' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -185,7 +185,7 @@ class WC_Geolocation {
|
||||||
$logger = wc_get_logger();
|
$logger = wc_get_logger();
|
||||||
|
|
||||||
if ( ! is_callable( 'gzopen' ) ) {
|
if ( ! is_callable( 'gzopen' ) ) {
|
||||||
$logger->notice( 'Server does not support gzopen', array( 'tag' => 'geolocation' ) );
|
$logger->notice( 'Server does not support gzopen', array( 'source' => 'geolocation' ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,13 +208,13 @@ class WC_Geolocation {
|
||||||
gzclose( $gzhandle );
|
gzclose( $gzhandle );
|
||||||
fclose( $handle );
|
fclose( $handle );
|
||||||
} else {
|
} else {
|
||||||
$logger->notice( 'Unable to open database file', array( 'tag' => 'geolocation' ) );
|
$logger->notice( 'Unable to open database file', array( 'source' => 'geolocation' ) );
|
||||||
}
|
}
|
||||||
@unlink( $tmp_database_path );
|
@unlink( $tmp_database_path );
|
||||||
} else {
|
} else {
|
||||||
$logger->notice(
|
$logger->notice(
|
||||||
'Unable to download GeoIP Database: ' . $tmp_database_path->get_error_message(),
|
'Unable to download GeoIP Database: ' . $tmp_database_path->get_error_message(),
|
||||||
array( 'tag' => 'geolocation' )
|
array( 'source' => 'geolocation' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,7 @@ class WC_Install {
|
||||||
foreach ( $update_callbacks as $update_callback ) {
|
foreach ( $update_callbacks as $update_callback ) {
|
||||||
$logger->info(
|
$logger->info(
|
||||||
sprintf( 'Queuing %s - %s', $version, $update_callback ),
|
sprintf( 'Queuing %s - %s', $version, $update_callback ),
|
||||||
array( 'tag' => 'wc_db_updates' )
|
array( 'source' => 'wc_db_updates' )
|
||||||
);
|
);
|
||||||
self::$background_updater->push_to_queue( $update_callback );
|
self::$background_updater->push_to_queue( $update_callback );
|
||||||
$update_queued = true;
|
$update_queued = true;
|
||||||
|
@ -609,7 +609,7 @@ CREATE TABLE {$wpdb->prefix}woocommerce_log (
|
||||||
log_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
log_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
timestamp datetime NOT NULL,
|
timestamp datetime NOT NULL,
|
||||||
level smallint(4) NOT NULL,
|
level smallint(4) NOT NULL,
|
||||||
tag varchar(255) NOT NULL,
|
source varchar(255) NOT NULL,
|
||||||
message longtext NOT NULL,
|
message longtext NOT NULL,
|
||||||
context longtext NULL,
|
context longtext NULL,
|
||||||
PRIMARY KEY (log_id),
|
PRIMARY KEY (log_id),
|
||||||
|
|
|
@ -73,7 +73,7 @@ class WC_Logger {
|
||||||
public function add( $handle, $message ) {
|
public function add( $handle, $message ) {
|
||||||
wc_deprecated_function( 'WC_Logger::add', '2.7', 'WC_Logger::log' );
|
wc_deprecated_function( 'WC_Logger::add', '2.7', 'WC_Logger::log' );
|
||||||
$message = apply_filters( 'woocommerce_logger_add_message', $message, $handle );
|
$message = apply_filters( 'woocommerce_logger_add_message', $message, $handle );
|
||||||
$this->log( WC_Log_Levels::NOTICE, $message, array( 'tag' => $handle, '_legacy' => true ) );
|
$this->log( WC_Log_Levels::NOTICE, $message, array( 'source' => $handle, '_legacy' => true ) );
|
||||||
wc_do_deprecated_action( 'woocommerce_log_add', array( $handle, $message ), '2.7', 'This action has been deprecated with no alternative.' );
|
wc_do_deprecated_action( 'woocommerce_log_add', array( $handle, $message ), '2.7', 'This action has been deprecated with no alternative.' );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,7 +418,7 @@ class WC_Email extends WC_Settings_API {
|
||||||
$content = $emogrifier->emogrify();
|
$content = $emogrifier->emogrify();
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
$logger = wc_get_logger();
|
$logger = wc_get_logger();
|
||||||
$logger->error( $e->getMessage(), array( 'tag' => 'emogrifier' ) );
|
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $content;
|
return $content;
|
||||||
|
|
|
@ -84,7 +84,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
||||||
if ( empty( self::$log ) ) {
|
if ( empty( self::$log ) ) {
|
||||||
self::$log = wc_get_logger();
|
self::$log = wc_get_logger();
|
||||||
}
|
}
|
||||||
self::$log->log( $level, $message, array( 'tag' => 'paypal' ) );
|
self::$log->log( $level, $message, array( 'source' => 'paypal' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,20 +23,20 @@ class WC_Log_Handler_DB extends WC_Log_Handler {
|
||||||
* @param array $context {
|
* @param array $context {
|
||||||
* Additional information for log handlers.
|
* Additional information for log handlers.
|
||||||
*
|
*
|
||||||
* @type string $tag Optional. Tag will be available in log table. Default '';
|
* @type string $source Optional. Source will be available in log table. Default '';
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @return bool False if value was not handled and true if value was handled.
|
* @return bool False if value was not handled and true if value was handled.
|
||||||
*/
|
*/
|
||||||
public function handle( $timestamp, $level, $message, $context ) {
|
public function handle( $timestamp, $level, $message, $context ) {
|
||||||
|
|
||||||
if ( isset( $context['tag'] ) && $context['tag'] ) {
|
if ( isset( $context['source'] ) && $context['source'] ) {
|
||||||
$tag = $context['tag'];
|
$source = $context['source'];
|
||||||
} else {
|
} else {
|
||||||
$tag = '';
|
$source = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->add( $timestamp, $level, $message, $tag, $context );
|
return $this->add( $timestamp, $level, $message, $source, $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,21 +45,21 @@ class WC_Log_Handler_DB extends WC_Log_Handler {
|
||||||
* @param int $timestamp Log timestamp.
|
* @param int $timestamp Log timestamp.
|
||||||
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
|
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
|
||||||
* @param string $message Log message.
|
* @param string $message Log message.
|
||||||
* @param string $tag Log tag. Useful for filtering and sorting.
|
* @param string $source Log source. Useful for filtering and sorting.
|
||||||
* @param array $context {
|
* @param array $context {
|
||||||
* Context will be serialized and stored in database.
|
* Context will be serialized and stored in database.
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @return bool True if write was successful.
|
* @return bool True if write was successful.
|
||||||
*/
|
*/
|
||||||
protected static function add( $timestamp, $level, $message, $tag, $context ) {
|
protected static function add( $timestamp, $level, $message, $source, $context ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$insert = array(
|
$insert = array(
|
||||||
'timestamp' => date( 'Y-m-d H:i:s', $timestamp ),
|
'timestamp' => date( 'Y-m-d H:i:s', $timestamp ),
|
||||||
'level' => WC_Log_Levels::get_level_severity( $level ),
|
'level' => WC_Log_Levels::get_level_severity( $level ),
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'tag' => $tag,
|
'source' => $source,
|
||||||
);
|
);
|
||||||
|
|
||||||
$format = array(
|
$format = array(
|
||||||
|
|
|
@ -76,7 +76,7 @@ class WC_Log_Handler_File extends WC_Log_Handler {
|
||||||
* @param array $context {
|
* @param array $context {
|
||||||
* Additional information for log handlers.
|
* Additional information for log handlers.
|
||||||
*
|
*
|
||||||
* @type string $tag Optional. Determines log file to write to. Default 'log'.
|
* @type string $source Optional. Determines log file to write to. Default 'log'.
|
||||||
* @type bool $_legacy Optional. Default false. True to use outdated log format
|
* @type bool $_legacy Optional. Default false. True to use outdated log format
|
||||||
* orignally used in deprecated WC_Logger::add calls.
|
* orignally used in deprecated WC_Logger::add calls.
|
||||||
* }
|
* }
|
||||||
|
@ -85,8 +85,8 @@ class WC_Log_Handler_File extends WC_Log_Handler {
|
||||||
*/
|
*/
|
||||||
public function handle( $timestamp, $level, $message, $context ) {
|
public function handle( $timestamp, $level, $message, $context ) {
|
||||||
|
|
||||||
if ( isset( $context['tag'] ) && $context['tag'] ) {
|
if ( isset( $context['source'] ) && $context['source'] ) {
|
||||||
$handle = $context['tag'];
|
$handle = $context['source'];
|
||||||
} else {
|
} else {
|
||||||
$handle = 'log';
|
$handle = 'log';
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ class WC_Log_Handler_File extends WC_Log_Handler {
|
||||||
protected static function format_entry( $timestamp, $level, $message, $context ) {
|
protected static function format_entry( $timestamp, $level, $message, $context ) {
|
||||||
|
|
||||||
if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) {
|
if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) {
|
||||||
if ( isset( $context['tag'] ) && $context['tag'] ) {
|
if ( isset( $context['source'] ) && $context['source'] ) {
|
||||||
$handle = $context['tag'];
|
$handle = $context['source'];
|
||||||
} else {
|
} else {
|
||||||
$handle = 'log';
|
$handle = 'log';
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,18 @@ class WC_Tests_Log_Handler_DB extends WC_Unit_Test_Case {
|
||||||
$time = time();
|
$time = time();
|
||||||
$context = array( 1, 2, 'a', 'b', 'key' => 'value' );
|
$context = array( 1, 2, 'a', 'b', 'key' => 'value' );
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', 'msg_debug', array( 'tag' => 'tag_debug' ) );
|
$handler->handle( $time, 'debug', 'msg_debug', array( 'source' => 'source_debug' ) );
|
||||||
$handler->handle( $time, 'info', 'msg_info', array( 'tag' => 'tag_info' ) );
|
$handler->handle( $time, 'info', 'msg_info', array( 'source' => 'source_info' ) );
|
||||||
$handler->handle( $time, 'notice', 'msg_notice', array( 'tag' => 'tag_notice' ) );
|
$handler->handle( $time, 'notice', 'msg_notice', array( 'source' => 'source_notice' ) );
|
||||||
$handler->handle( $time, 'warning', 'msg_warning', array( 'tag' => 'tag_warning' ) );
|
$handler->handle( $time, 'warning', 'msg_warning', array( 'source' => 'source_warning' ) );
|
||||||
$handler->handle( $time, 'error', 'msg_error', array( 'tag' => 'tag_error' ) );
|
$handler->handle( $time, 'error', 'msg_error', array( 'source' => 'source_error' ) );
|
||||||
$handler->handle( $time, 'critical', 'msg_critical', array( 'tag' => 'tag_critical' ) );
|
$handler->handle( $time, 'critical', 'msg_critical', array( 'source' => 'source_critical' ) );
|
||||||
$handler->handle( $time, 'alert', 'msg_alert', array( 'tag' => 'tag_alert' ) );
|
$handler->handle( $time, 'alert', 'msg_alert', array( 'source' => 'source_alert' ) );
|
||||||
$handler->handle( $time, 'emergency', 'msg_emergency', array( 'tag' => 'tag_emergency' ) );
|
$handler->handle( $time, 'emergency', 'msg_emergency', array( 'source' => 'source_emergency' ) );
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', 'context_test', $context );
|
$handler->handle( $time, 'debug', 'context_test', $context );
|
||||||
|
|
||||||
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, tag, context FROM {$wpdb->prefix}woocommerce_log", ARRAY_A );
|
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, source, context FROM {$wpdb->prefix}woocommerce_log", ARRAY_A );
|
||||||
|
|
||||||
$expected_ts = date( 'Y-m-d H:i:s', $time );
|
$expected_ts = date( 'Y-m-d H:i:s', $time );
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -43,63 +43,63 @@ class WC_Tests_Log_Handler_DB extends WC_Unit_Test_Case {
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'debug' ),
|
'level' => WC_Log_Levels::get_level_severity( 'debug' ),
|
||||||
'message' => 'msg_debug',
|
'message' => 'msg_debug',
|
||||||
'tag' => 'tag_debug',
|
'source' => 'source_debug',
|
||||||
'context' => serialize( array( 'tag' => 'tag_debug' ) ),
|
'context' => serialize( array( 'source' => 'source_debug' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'info' ),
|
'level' => WC_Log_Levels::get_level_severity( 'info' ),
|
||||||
'message' => 'msg_info',
|
'message' => 'msg_info',
|
||||||
'tag' => 'tag_info',
|
'source' => 'source_info',
|
||||||
'context' => serialize( array( 'tag' => 'tag_info' ) ),
|
'context' => serialize( array( 'source' => 'source_info' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'notice' ),
|
'level' => WC_Log_Levels::get_level_severity( 'notice' ),
|
||||||
'message' => 'msg_notice',
|
'message' => 'msg_notice',
|
||||||
'tag' => 'tag_notice',
|
'source' => 'source_notice',
|
||||||
'context' => serialize( array( 'tag' => 'tag_notice' ) ),
|
'context' => serialize( array( 'source' => 'source_notice' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'warning' ),
|
'level' => WC_Log_Levels::get_level_severity( 'warning' ),
|
||||||
'message' => 'msg_warning',
|
'message' => 'msg_warning',
|
||||||
'tag' => 'tag_warning',
|
'source' => 'source_warning',
|
||||||
'context' => serialize( array( 'tag' => 'tag_warning' ) ),
|
'context' => serialize( array( 'source' => 'source_warning' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'error' ),
|
'level' => WC_Log_Levels::get_level_severity( 'error' ),
|
||||||
'message' => 'msg_error',
|
'message' => 'msg_error',
|
||||||
'tag' => 'tag_error',
|
'source' => 'source_error',
|
||||||
'context' => serialize( array( 'tag' => 'tag_error' ) ),
|
'context' => serialize( array( 'source' => 'source_error' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'critical' ),
|
'level' => WC_Log_Levels::get_level_severity( 'critical' ),
|
||||||
'message' => 'msg_critical',
|
'message' => 'msg_critical',
|
||||||
'tag' => 'tag_critical',
|
'source' => 'source_critical',
|
||||||
'context' => serialize( array( 'tag' => 'tag_critical' ) ),
|
'context' => serialize( array( 'source' => 'source_critical' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'alert' ),
|
'level' => WC_Log_Levels::get_level_severity( 'alert' ),
|
||||||
'message' => 'msg_alert',
|
'message' => 'msg_alert',
|
||||||
'tag' => 'tag_alert',
|
'source' => 'source_alert',
|
||||||
'context' => serialize( array( 'tag' => 'tag_alert' ) ),
|
'context' => serialize( array( 'source' => 'source_alert' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'emergency' ),
|
'level' => WC_Log_Levels::get_level_severity( 'emergency' ),
|
||||||
'message' => 'msg_emergency',
|
'message' => 'msg_emergency',
|
||||||
'tag' => 'tag_emergency',
|
'source' => 'source_emergency',
|
||||||
'context' => serialize( array( 'tag' => 'tag_emergency' ) ),
|
'context' => serialize( array( 'source' => 'source_emergency' ) ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'timestamp' => $expected_ts,
|
'timestamp' => $expected_ts,
|
||||||
'level' => WC_Log_Levels::get_level_severity( 'debug' ),
|
'level' => WC_Log_Levels::get_level_severity( 'debug' ),
|
||||||
'message' => 'context_test',
|
'message' => 'context_test',
|
||||||
'tag' => '',
|
'source' => '',
|
||||||
'context' => serialize( $context ),
|
'context' => serialize( $context ),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -121,12 +121,12 @@ class WC_Tests_Log_Handler_DB extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', '', array() );
|
$handler->handle( $time, 'debug', '', array() );
|
||||||
|
|
||||||
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, tag FROM {$wpdb->prefix}woocommerce_log" );
|
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, source FROM {$wpdb->prefix}woocommerce_log" );
|
||||||
$this->assertCount( 1, $log_entries );
|
$this->assertCount( 1, $log_entries );
|
||||||
|
|
||||||
WC_Log_Handler_DB::flush();
|
WC_Log_Handler_DB::flush();
|
||||||
|
|
||||||
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, tag FROM {$wpdb->prefix}woocommerce_log" );
|
$log_entries = $wpdb->get_results( "SELECT timestamp, level, message, source FROM {$wpdb->prefix}woocommerce_log" );
|
||||||
$this->assertCount( 0, $log_entries );
|
$this->assertCount( 0, $log_entries );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
public function test_legacy_format() {
|
public function test_legacy_format() {
|
||||||
$handler = new WC_Log_Handler_File( array( 'threshold' => 'debug' ) );
|
$handler = new WC_Log_Handler_File( array( 'threshold' => 'debug' ) );
|
||||||
|
|
||||||
$handler->handle( time(), 'info', 'this is a message', array( 'tag' => 'unit-tests', '_legacy' => true ) );
|
$handler->handle( time(), 'info', 'this is a message', array( 'source' => 'unit-tests', '_legacy' => true ) );
|
||||||
|
|
||||||
$this->assertStringMatchesFormat( '%d-%d-%d @ %d:%d:%d - %s', $this->read_content( 'unit-tests' ) );
|
$this->assertStringMatchesFormat( '%d-%d-%d @ %d:%d:%d - %s', $this->read_content( 'unit-tests' ) );
|
||||||
$this->assertStringEndsWith( ' - this is a message' . PHP_EOL, $this->read_content( 'unit-tests' ) );
|
$this->assertStringEndsWith( ' - this is a message' . PHP_EOL, $this->read_content( 'unit-tests' ) );
|
||||||
|
@ -61,7 +61,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
public function test_clear() {
|
public function test_clear() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$log_name = '_test_clear';
|
$log_name = '_test_clear';
|
||||||
$handler->handle( time(), 'debug', 'debug', array( 'tag' => $log_name ) );
|
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
||||||
$handler->clear( $log_name );
|
$handler->clear( $log_name );
|
||||||
$this->assertEquals( '', $this->read_content( $log_name ) );
|
$this->assertEquals( '', $this->read_content( $log_name ) );
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
public function test_remove() {
|
public function test_remove() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$log_name = '_test_remove';
|
$log_name = '_test_remove';
|
||||||
$handler->handle( time(), 'debug', 'debug', array( 'tag' => $log_name ) );
|
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
||||||
$handler->remove( $log_name );
|
$handler->remove( $log_name );
|
||||||
$this->assertFileNotExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
$this->assertFileNotExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
||||||
}
|
}
|
||||||
|
@ -102,23 +102,23 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 'tag' context determines log file.
|
* Test 'source' context determines log file.
|
||||||
*
|
*
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
*/
|
*/
|
||||||
public function test_log_file_tag() {
|
public function test_log_file_source() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$time = time();
|
$time = time();
|
||||||
$context_tag = array( 'tag' => 'unit-tests' );
|
$context_source = array( 'source' => 'unit-tests' );
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', 'debug', $context_tag );
|
$handler->handle( $time, 'debug', 'debug', $context_source );
|
||||||
$handler->handle( $time, 'info', 'info', $context_tag );
|
$handler->handle( $time, 'info', 'info', $context_source );
|
||||||
$handler->handle( $time, 'notice', 'notice', $context_tag );
|
$handler->handle( $time, 'notice', 'notice', $context_source );
|
||||||
$handler->handle( $time, 'warning', 'warning', $context_tag );
|
$handler->handle( $time, 'warning', 'warning', $context_source );
|
||||||
$handler->handle( $time, 'error', 'error', $context_tag );
|
$handler->handle( $time, 'error', 'error', $context_source );
|
||||||
$handler->handle( $time, 'critical', 'critical', $context_tag );
|
$handler->handle( $time, 'critical', 'critical', $context_source );
|
||||||
$handler->handle( $time, 'alert', 'alert', $context_tag );
|
$handler->handle( $time, 'alert', 'alert', $context_source );
|
||||||
$handler->handle( $time, 'emergency', 'emergency', $context_tag );
|
$handler->handle( $time, 'emergency', 'emergency', $context_source );
|
||||||
|
|
||||||
$log_content = $this->read_content( 'unit-tests' );
|
$log_content = $this->read_content( 'unit-tests' );
|
||||||
$this->assertStringMatchesFormatFile( dirname( __FILE__ ) . '/test_log_expected.txt', $log_content );
|
$this->assertStringMatchesFormatFile( dirname( __FILE__ ) . '/test_log_expected.txt', $log_content );
|
||||||
|
@ -133,17 +133,17 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
$handler_a = new WC_Log_Handler_File();
|
$handler_a = new WC_Log_Handler_File();
|
||||||
$handler_b = new WC_Log_Handler_File();
|
$handler_b = new WC_Log_Handler_File();
|
||||||
$time = time();
|
$time = time();
|
||||||
$context_tag = array( 'tag' => 'unit-tests' );
|
$context_source = array( 'source' => 'unit-tests' );
|
||||||
|
|
||||||
// Different loggers should not conflict.
|
// Different loggers should not conflict.
|
||||||
$handler_a->handle( $time, 'debug', 'debug', $context_tag );
|
$handler_a->handle( $time, 'debug', 'debug', $context_source );
|
||||||
$handler_b->handle( $time, 'info', 'info', $context_tag );
|
$handler_b->handle( $time, 'info', 'info', $context_source );
|
||||||
$handler_a->handle( $time, 'notice', 'notice', $context_tag );
|
$handler_a->handle( $time, 'notice', 'notice', $context_source );
|
||||||
$handler_b->handle( $time, 'warning', 'warning', $context_tag );
|
$handler_b->handle( $time, 'warning', 'warning', $context_source );
|
||||||
$handler_a->handle( $time, 'error', 'error', $context_tag );
|
$handler_a->handle( $time, 'error', 'error', $context_source );
|
||||||
$handler_b->handle( $time, 'critical', 'critical', $context_tag );
|
$handler_b->handle( $time, 'critical', 'critical', $context_source );
|
||||||
$handler_a->handle( $time, 'alert', 'alert', $context_tag );
|
$handler_a->handle( $time, 'alert', 'alert', $context_source );
|
||||||
$handler_b->handle( $time, 'emergency', 'emergency', $context_tag );
|
$handler_b->handle( $time, 'emergency', 'emergency', $context_source );
|
||||||
|
|
||||||
$log_content = $this->read_content( 'unit-tests' );
|
$log_content = $this->read_content( 'unit-tests' );
|
||||||
$this->assertStringMatchesFormatFile( dirname( __FILE__ ) . '/test_log_expected.txt', $log_content );
|
$this->assertStringMatchesFormatFile( dirname( __FILE__ ) . '/test_log_expected.txt', $log_content );
|
||||||
|
@ -175,8 +175,8 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
file_put_contents( WC_Log_Handler_File::get_log_file_path( $log_name . ".{$i}" ), $i );
|
file_put_contents( WC_Log_Handler_File::get_log_file_path( $log_name . ".{$i}" ), $i );
|
||||||
}
|
}
|
||||||
|
|
||||||
$context_tag = array( 'tag' => $log_name );
|
$context_source = array( 'source' => $log_name );
|
||||||
$handler->handle( $time, 'emergency', 'emergency', $context_tag );
|
$handler->handle( $time, 'emergency', 'emergency', $context_source );
|
||||||
|
|
||||||
$this->assertFileExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
$this->assertFileExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'notice' ),
|
$this->equalTo( 'notice' ),
|
||||||
$this->equalTo( 'this is a message' ),
|
$this->equalTo( 'this is a message' ),
|
||||||
$this->equalTo( array( 'tag' => 'unit-tests', '_legacy' => true ) )
|
$this->equalTo( array( 'source' => 'unit-tests', '_legacy' => true ) )
|
||||||
);
|
);
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue