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
|
|
|
|
*/
|
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.
|
|
|
|
*
|
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-12-16 20:34:15 +00:00
|
|
|
protected static function format_entry( $timestamp, $level, $message, $context ) {
|
2016-12-16 19:44:09 +00:00
|
|
|
$time_string = self::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
|
|
|
}
|
|
|
|
}
|