2016-11-12 19:46:58 +00:00
|
|
|
<?php
|
2018-03-05 11:36:56 +00:00
|
|
|
/**
|
|
|
|
* Log handling functionality.
|
|
|
|
*
|
|
|
|
* @class WC_Log_Handler
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Abstracts
|
2018-03-05 11:36:56 +00:00
|
|
|
*/
|
|
|
|
|
2016-11-12 19:46:58 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2018-03-05 11:36:56 +00:00
|
|
|
exit; // Exit if accessed directly.
|
2016-11-12 19:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract WC Log Handler Class
|
|
|
|
*
|
2016-11-20 20:36:23 +00:00
|
|
|
* @version 1.0.0
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Abstracts
|
2016-11-12 19:46:58 +00:00
|
|
|
*/
|
2017-01-24 13:10:00 +00:00
|
|
|
abstract class WC_Log_Handler implements WC_Log_Handler_Interface {
|
2016-11-12 19:46:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a timestamp for use in log messages.
|
|
|
|
*
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param int $timestamp Log timestamp.
|
|
|
|
* @return string Formatted time for use in log entry.
|
2016-11-12 19:46:58 +00:00
|
|
|
*/
|
2016-12-16 20:34:15 +00:00
|
|
|
protected static function format_time( $timestamp ) {
|
2016-11-12 19:46:58 +00:00
|
|
|
return date( 'c', $timestamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a log entry text from level, timestamp and message.
|
|
|
|
*
|
2018-03-05 11:36:56 +00:00
|
|
|
* @param int $timestamp Log timestamp.
|
|
|
|
* @param string $level emergency|alert|critical|error|warning|notice|info|debug.
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param string $message Log message.
|
2018-03-05 11:36:56 +00:00
|
|
|
* @param array $context Additional information for log handlers.
|
2016-11-12 19:46:58 +00:00
|
|
|
*
|
2016-11-20 13:32:46 +00:00
|
|
|
* @return string Formatted log entry.
|
2016-11-12 19:46:58 +00:00
|
|
|
*/
|
2016-12-16 20:34:15 +00:00
|
|
|
protected static function format_entry( $timestamp, $level, $message, $context ) {
|
2019-12-20 17:21:08 +00:00
|
|
|
$time_string = self::format_time( $timestamp );
|
2016-11-13 17:45:45 +00:00
|
|
|
$level_string = strtoupper( $level );
|
2019-12-20 17:21:08 +00:00
|
|
|
$entry = "{$time_string} {$level_string} {$message}";
|
2016-11-20 20:38:26 +00:00
|
|
|
|
2019-12-20 18:25:23 +00:00
|
|
|
return apply_filters(
|
|
|
|
'woocommerce_format_log_entry',
|
|
|
|
$entry,
|
|
|
|
array(
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'level' => $level,
|
|
|
|
'message' => $message,
|
|
|
|
'context' => $context,
|
|
|
|
)
|
|
|
|
);
|
2016-11-12 19:46:58 +00:00
|
|
|
}
|
|
|
|
}
|