| @@ -1,57 +1,57 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Log handling functionality. | |
| 4 | - * | |
| 5 | - * @class Cartflows_Log_Handler | |
| 6 | - * @package WooCommerce/Abstracts | |
| 7 | - */ | |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; // Exit if accessed directly. | |
| 11 | -} | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * Abstract WC Log Handler Class | |
| 15 | - * | |
| 16 | - * @version 1.0.0 | |
| 17 | - * @package WooCommerce/Abstracts | |
| 18 | - */ | |
| 19 | -abstract class Cartflows_Log_Handler implements Cartflows_Log_Handler_Interface { | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * Formats a timestamp for use in log messages. | |
| 23 | - * | |
| 24 | - * @param int $timestamp Log timestamp. | |
| 25 | - * @return string Formatted time for use in log entry. | |
| 26 | - */ | |
| 27 | - protected static function format_time( $timestamp ) { | |
| 28 | - return date( 'c', $timestamp ); | |
| 29 | - } | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Builds a log entry text from level, timestamp and message. | |
| 33 | - * | |
| 34 | - * @param int $timestamp Log timestamp. | |
| 35 | - * @param string $level emergency|alert|critical|error|warning|notice|info|debug. | |
| 36 | - * @param string $message Log message. | |
| 37 | - * @param array $context Additional information for log handlers. | |
| 38 | - * | |
| 39 | - * @return string Formatted log entry. | |
| 40 | - */ | |
| 41 | - protected static function format_entry( $timestamp, $level, $message, $context ) { | |
| 42 | - $time_string = self::format_time( $timestamp ); | |
| 43 | - $level_string = strtoupper( $level ); | |
| 44 | - $entry = "{$time_string} {$level_string} {$message}"; | |
| 45 | - | |
| 46 | - return apply_filters( | |
| 47 | - 'cartflows_format_log_entry', | |
| 48 | - $entry, | |
| 49 | - array( | |
| 50 | - 'timestamp' => $timestamp, | |
| 51 | - 'level' => $level, | |
| 52 | - 'message' => $message, | |
| 53 | - 'context' => $context, | |
| 54 | - ) | |
| 55 | - ); | |
| 56 | - } | |
| 57 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Log handling functionality. | |
| 4 | + * | |
| 5 | + * @class Cartflows_Log_Handler | |
| 6 | + * @package WooCommerce/Abstracts | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; // Exit if accessed directly. | |
| 11 | +} | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Abstract WC Log Handler Class | |
| 15 | + * | |
| 16 | + * @version 1.0.0 | |
| 17 | + * @package WooCommerce/Abstracts | |
| 18 | + */ | |
| 19 | +abstract class Cartflows_Log_Handler implements Cartflows_Log_Handler_Interface { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Formats a timestamp for use in log messages. | |
| 23 | + * | |
| 24 | + * @param int $timestamp Log timestamp. | |
| 25 | + * @return string Formatted time for use in log entry. | |
| 26 | + */ | |
| 27 | + protected static function format_time( $timestamp ) { | |
| 28 | + return gmdate( 'c', $timestamp ); | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Builds a log entry text from level, timestamp and message. | |
| 33 | + * | |
| 34 | + * @param int $timestamp Log timestamp. | |
| 35 | + * @param string $level emergency|alert|critical|error|warning|notice|info|debug. | |
| 36 | + * @param string $message Log message. | |
| 37 | + * @param array $context Additional information for log handlers. | |
| 38 | + * | |
| 39 | + * @return string Formatted log entry. | |
| 40 | + */ | |
| 41 | + protected static function format_entry( $timestamp, $level, $message, $context ) { | |
| 42 | + $time_string = self::format_time( $timestamp ); | |
| 43 | + $level_string = strtoupper( $level ); | |
| 44 | + $entry = "{$time_string} {$level_string} {$message}"; | |
| 45 | + | |
| 46 | + return apply_filters( | |
| 47 | + 'cartflows_format_log_entry', | |
| 48 | + $entry, | |
| 49 | + array( | |
| 50 | + 'timestamp' => $timestamp, | |
| 51 | + 'level' => $level, | |
| 52 | + 'message' => $message, | |
| 53 | + 'context' => $context, | |
| 54 | + ) | |
| 55 | + ); | |
| 56 | + } | |
| 57 | +} | |