2016-11-12 19:46:58 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract WC Log Handler Class
|
|
|
|
*
|
2016-11-20 20:36:23 +00:00
|
|
|
* @version 1.0.0
|
2016-11-12 19:46:58 +00:00
|
|
|
* @package WooCommerce/Abstracts
|
|
|
|
* @category Abstract Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
abstract class WC_Log_Handler {
|
|
|
|
|
2016-11-13 12:46:06 +00:00
|
|
|
|
2016-11-12 19:46:58 +00:00
|
|
|
/**
|
|
|
|
* Handle a log entry.
|
|
|
|
*
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param int $timestamp Log timestamp.
|
2016-11-12 19:46:58 +00:00
|
|
|
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param string $message Log message.
|
|
|
|
* @param array $context Additional information for log handlers.
|
2016-11-12 19:46:58 +00:00
|
|
|
*
|
2016-12-10 21:21:41 +00:00
|
|
|
* @return bool True on success.
|
2016-11-12 19:46:58 +00:00
|
|
|
*/
|
2016-11-20 13:32:46 +00:00
|
|
|
abstract public function handle( $timestamp, $level, $message, $context );
|
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
|
|
|
*/
|
|
|
|
public static function format_time( $timestamp ) {
|
|
|
|
return date( 'c', $timestamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a log entry text from level, timestamp and message.
|
|
|
|
*
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param int $timestamp Log timestamp.
|
2016-11-12 19:46:58 +00:00
|
|
|
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
|
2016-11-20 13:32:46 +00:00
|
|
|
* @param string $message Log message.
|
|
|
|
* @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-11-20 13:32:46 +00:00
|
|
|
public function format_entry( $timestamp, $level, $message, $context ) {
|
2016-11-12 19:46:58 +00:00
|
|
|
$time_string = $this->format_time( $timestamp );
|
2016-11-13 17:45:45 +00:00
|
|
|
$level_string = strtoupper( $level );
|
2016-11-20 20:38:26 +00:00
|
|
|
$entry = "{$time_string} {$level_string} {$message}";
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|