File manager - Edit - /home/theblueo/tv/fb4e3b/logger.tar
Back
items/log-item-interface.php 0000666 00000002307 15214176026 0012063 0 ustar 00 <?php namespace Elementor\Core\Logger\Items; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Interface Log_Item_Interface * * @package Elementor\Core\Logger * * @property string $date * @property string $type * @property string $message * @property int $times * @property array $meta * @property array $times_dates * @property array $args * */ interface Log_Item_Interface extends \JsonSerializable { const MAX_LOG_ENTRIES = 42; /** * Log_Item_Interface constructor. * * @param array $args */ public function __construct( $args ); /** * @param string $name * * @return string */ public function __get( $name ); /** * @return string */ public function __toString(); /** * @param $str * @return Log_Item_Interface | null */ public static function from_json( $str ); /** * @param string $format * @return string */ public function format( $format = 'html' ); /** * @return string */ public function get_fingerprint(); /** * @param Log_Item_Interface $item * @param bool $truncate */ public function increase_times( $item, $truncate = true ); /** * @return string */ public function get_name(); } items/php.php 0000666 00000000412 15214176026 0007172 0 ustar 00 <?php namespace Elementor\Core\Logger\Items; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class PHP extends File { const FORMAT = 'PHP: date [type X times][file::line] message [meta]'; public function get_name() { return 'PHP'; } } items/js.php 0000666 00000001504 15214176026 0007022 0 ustar 00 <?php namespace Elementor\Core\Logger\Items; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class JS extends File { const FORMAT = 'JS: date [type X times][file:line:column] message [meta]'; protected $column; public function __construct( $args ) { parent::__construct( $args ); $this->column = $args['column']; $this->file = $args['url']; $this->date = gmdate( 'Y-m-d H:i:s', $args['timestamp'] ); } public function jsonSerialize() { $json_arr = parent::jsonSerialize(); $json_arr['column'] = $this->column; return $json_arr; } public function deserialize( $properties ) { parent::deserialize( $properties ); $this->column = ! empty( $properties['column'] ) && is_string( $properties['column'] ) ? $properties['column'] : ''; } public function get_name() { return 'JS'; } } items/base.php 0000666 00000012243 15214176026 0007322 0 ustar 00 <?php namespace Elementor\Core\Logger\Items; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Base implements Log_Item_Interface { const FORMAT = 'date [type] message [meta]'; const TRACE_FORMAT = '#key: file(line): class type function()'; const TRACE_LIMIT = 5; protected $date; protected $type; protected $message; protected $meta = []; protected $times = 0; protected $times_dates = []; protected $args = []; public function __construct( $args ) { $this->date = current_time( 'mysql' ); $this->message = ! empty( $args['message'] ) ? esc_html( $args['message'] ) : ''; $this->type = ! empty( $args['type'] ) ? $args['type'] : 'info'; $this->meta = ! empty( $args['meta'] ) ? $args['meta'] : []; $this->args = $args; $this->set_trace(); } public function __get( $name ) { if ( property_exists( $this, $name ) ) { return $this->{$name}; } return ''; } public function __toString() { $vars = get_object_vars( $this ); return strtr( static::FORMAT, $vars ); } public function jsonSerialize() { return [ 'class' => get_class( $this ), 'item' => [ 'date' => $this->date, 'message' => $this->message, 'type' => $this->type, 'meta' => $this->meta, 'times' => $this->times, 'times_dates' => $this->times_dates, 'args' => $this->args, ], ]; } public function deserialize( $properties ) { $this->date = ! empty( $properties['date'] ) && is_string( $properties['date'] ) ? $properties['date'] : ''; $this->message = ! empty( $properties['message'] ) && is_string( $properties['message'] ) ? $properties['message'] : ''; $this->type = ! empty( $properties['type'] ) && is_string( $properties['type'] ) ? $properties['type'] : ''; $this->meta = ! empty( $properties['meta'] ) && is_array( $properties['meta'] ) ? $properties['meta'] : []; $this->times = ! empty( $properties['times'] ) && is_string( $properties['times'] ) ? $properties['times'] : ''; $this->times_dates = ! empty( $properties['times_dates'] ) && is_array( $properties['times_dates'] ) ? $properties['times_dates'] : []; $this->args = ! empty( $properties['args'] ) && is_array( $properties['args'] ) ? $properties['args'] : []; } /** * @return Log_Item_Interface | null */ public static function from_json( $str ) { $obj = json_decode( $str, true ); if ( ! array_key_exists( 'class', $obj ) ) { return null; } $class = $obj['class']; if ( class_exists( $class ) ) { /** @var Base $item */ $item = new $class( $obj['item']['message'] ); $item->deserialize( $obj['item'] ); return $item; } return null; } public function to_formatted_string( $output_format = 'html' ) { $vars = get_object_vars( $this ); $format = static::FORMAT; if ( 'html' === $output_format ) { $format = str_replace( 'message', '<strong>message</strong>', static::FORMAT ); } if ( empty( $vars['meta'] ) ) { $format = str_replace( '[meta]', '', $format ); } else { $vars['meta'] = stripslashes( var_export( $vars['meta'], true ) ); // @codingStandardsIgnoreLine } return strtr( $format, $vars ); } public function get_fingerprint() { $unique_key = $this->type . $this->message . var_export( $this->meta, true ); // @codingStandardsIgnoreLine //info messages are not be aggregated: if ( 'info' === $this->type ) { $unique_key .= $this->date; } return md5( $unique_key ); } public function increase_times( $item, $truncate = true ) { $this->times++; $this->times_dates[] = $item->date; if ( $truncate && ( self::MAX_LOG_ENTRIES < count( $this->times_dates ) ) ) { $this->times_dates = array_slice( $this->times_dates, -self::MAX_LOG_ENTRIES ); } } public function format( $format = 'html' ) { $trace = $this->format_trace(); if ( empty( $trace ) ) { return $this->to_formatted_string( $format ); } $copy = clone $this; $copy->meta['trace'] = $trace; return $copy->to_formatted_string( $format ); } public function get_name() { return 'Log'; } private function format_trace() { $trace = empty( $this->meta['trace'] ) ? '' : $this->meta['trace']; if ( is_string( $trace ) ) { return $trace; } $trace_str = ''; foreach ( $trace as $key => $trace_line ) { $format = static::TRACE_FORMAT; $trace_line['key'] = $key; if ( empty( $trace_line['file'] ) ) { $format = str_replace( 'file(line): ', '', $format ); } $trace_str .= PHP_EOL . strtr( $format, $trace_line ); $trace_str .= empty( $trace_line['args'] ) ? '' : var_export( $trace_line['args'], true ); // @codingStandardsIgnoreLine } return $trace_str . PHP_EOL; } private function set_trace() { if ( ! empty( $this->args['trace'] ) && true === $this->args['trace'] ) { $limit = empty( $this->args['trace_limit'] ) ? static::TRACE_LIMIT : $this->args['trace_limit']; $stack = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // @codingStandardsIgnoreLine while ( ! empty( $stack ) && ! empty( $stack[0]['file'] ) && ( false !== strpos( $stack[0]['file'], 'core' . DIRECTORY_SEPARATOR . 'logger' ) ) ) { array_shift( $stack ); } $this->meta['trace'] = array_slice( $stack, 0, $limit ); return; } if ( is_array( $this->args ) ) { unset( $this->args['trace'] ); } } } items/file.php 0000666 00000001720 15214176026 0007325 0 ustar 00 <?php namespace Elementor\Core\Logger\Items; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class File extends Base { const FORMAT = 'date [type X times][file:line] message [meta]'; protected $file; protected $line; public function __construct( $args ) { parent::__construct( $args ); $this->file = empty( $args['file'] ) ? '' : $args['file']; $this->line = empty( $args['line'] ) ? '' : $args['line']; } public function jsonSerialize() { $json_arr = parent::jsonSerialize(); $json_arr['file'] = $this->file; $json_arr['line'] = $this->line; return $json_arr; } public function deserialize( $properties ) { parent::deserialize( $properties ); $this->file = ! empty( $properties['file'] ) && is_string( $properties['file'] ) ? $properties['file'] : ''; $this->line = ! empty( $properties['line'] ) && is_string( $properties['line'] ) ? $properties['line'] : ''; } public function get_name() { return 'File'; } } log-reporter.php 0000666 00000005570 15214176026 0007715 0 ustar 00 <?php namespace Elementor\Core\Logger; use Elementor\Modules\System_Info\Reporters\Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor Log reporter. * * Elementor log reporter handler class is responsible for generating the * debug reports. * * @since 2.4.0 */ class Log_Reporter extends Base { const MAX_ENTRIES = 20; const CLEAR_LOG_ACTION = 'elementor-clear-log'; public function get_title() { $title = 'Log'; if ( 'html' === $this->_properties['format'] && empty( $_GET[ self::CLEAR_LOG_ACTION ] ) ) { // phpcs:ignore -- nonce validation is not require here. $nonce = wp_create_nonce( self::CLEAR_LOG_ACTION ); $url = add_query_arg( [ self::CLEAR_LOG_ACTION => 1, '_wpnonce' => $nonce, ] ); $title .= '<a href="' . esc_url( $url ) . '#elementor-clear-log" class="box-title-tool">' . __( 'Clear Log', 'elementor' ) . '</a>'; $title .= '<span id="elementor-clear-log"></span>'; } return $title; } public function get_fields() { return [ 'log_entries' => '', ]; } public function get_log_entries() { /** @var \Elementor\Core\Logger\Manager $manager */ $manager = Manager::instance(); /** @var \Elementor\Core\Logger\Loggers\Db $logger */ $logger = $manager->get_logger( 'db' ); if ( ! empty( $_GET[ self::CLEAR_LOG_ACTION ] ) ) { if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], self::CLEAR_LOG_ACTION ) ) { wp_die( 'Invalid Nonce', 'Invalid Nonce', [ 'back_link' => true, ] ); } $logger->clear(); } $log_string = 'No entries to display'; $log_entries = $logger->get_formatted_log_entries( self::MAX_ENTRIES, false ); if ( ! empty( $log_entries ) ) { $entries_string = ''; foreach ( $log_entries as $key => $log_entry ) { if ( $log_entry['count'] ) { $entries_string .= '<h3>' . sprintf( '%s: showing %s of %s', $key, $log_entry['count'], $log_entry['total_count'] ) . '</h3>'; $entries_string .= '<div class="elementor-log-entries">' . $log_entry['entries'] . '</div>'; } } if ( ! empty( $entries_string ) ) { $log_string = $entries_string; } } return [ 'value' => $log_string, ]; } public function get_raw_log_entries() { $log_string = 'No entries to display'; /** @var \Elementor\Core\Logger\Manager $manager */ $manager = Manager::instance(); $logger = $manager->get_logger(); $log_entries = $logger->get_formatted_log_entries( self::MAX_ENTRIES, false ); if ( ! empty( $log_entries ) ) { $entries_string = PHP_EOL; foreach ( $log_entries as $key => $log_entry ) { if ( $log_entry['count'] ) { $entries_string .= sprintf( '%s: showing %s of %s', $key, $log_entry['count'], $log_entry['total_count'] ) . $log_entry['entries'] . PHP_EOL; } } if ( ! empty( $entries_string ) ) { $log_string = $entries_string; } } return [ 'value' => $log_string, ]; } } loggers/base.php 0000666 00000004523 15214176026 0007645 0 ustar 00 <?php namespace Elementor\Core\Logger\Loggers; use Elementor\Core\Logger\Items\Base as Log_Item; use Elementor\Core\Logger\Items\Log_Item_Interface as Log_Item_Interface; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } abstract class Base implements Logger_Interface { abstract protected function save_log( Log_Item_Interface $item ); /** * @return Log_Item_Interface[] */ abstract protected function get_log(); public function log( $item, $type = self::LEVEL_INFO, $args = [] ) { if ( ! $item instanceof Log_Item ) { $item = $this->create_item( $item, $type, $args ); } $this->save_log( $item ); } public function info( $message, $args = [] ) { $this->log( $message, self::LEVEL_INFO, $args ); } public function notice( $message, $args = [] ) { $this->log( $message, self::LEVEL_NOTICE, $args ); } public function warning( $message, $args = [] ) { $this->log( $message, self::LEVEL_WARNING, $args ); } public function error( $message, $args = [] ) { $this->log( $message, self::LEVEL_ERROR, $args ); } /** * @param string $message * @param string $type * @param array $args * * @return Log_Item_Interface */ private function create_item( $message, $type, $args = [] ) { $args['message'] = $message; $args['type'] = $type; $item = new Log_Item( $args ); return $item; } public function get_formatted_log_entries( $max_entries, $table = true ) { $entries = $this->get_log(); if ( empty( $entries ) ) { return [ 'All' => [ 'total_count' => 0, 'count' => 0, 'entries' => '', ], ]; } $sorted_entries = []; $open_tag = $table ? '<tr><td>' : ''; $close_tab = $table ? '</td></tr>' : PHP_EOL; $format = $table ? 'html' : 'raw'; foreach ( $entries as $entry ) { /** @var Log_Item $entry */ $sorted_entries[ $entry->get_name() ][] = $open_tag . $entry->format( $format ) . $close_tab; } $formatted_entries = []; foreach ( $sorted_entries as $key => $sorted_entry ) { $formatted_entries[ $key ]['total_count'] = count( $sorted_entry ); $formatted_entries[ $key ]['count'] = count( $sorted_entry ); $sorted_entry = array_slice( $sorted_entry, -$max_entries ); $formatted_entries[ $key ]['count'] = count( $sorted_entry ); $formatted_entries[ $key ]['entries'] = implode( $sorted_entry ); } return $formatted_entries; } } loggers/db.php 0000666 00000002011 15214176026 0007306 0 ustar 00 <?php namespace Elementor\Core\Logger\Loggers; use Elementor\Core\Logger\Items\Log_Item_Interface as Log_Item; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Db extends Base { public function save_log( Log_Item $item ) { $log = $this->maybe_truncate_log(); $id = $item->get_fingerprint(); if ( empty( $log[ $id ] ) ) { $log[ $id ] = $item; } $log[ $id ]->increase_times( $item ); update_option( self::LOG_NAME, $log, 'no' ); } public function clear() { delete_option( self::LOG_NAME ); } private function maybe_truncate_log() { /** @var Log_Item[] $log */ $log = $this->get_log(); if ( Log_Item::MAX_LOG_ENTRIES < count( $log ) ) { $log = array_slice( $log, -Log_Item::MAX_LOG_ENTRIES ); } return $log; } protected function get_log() { // Clear cache. wp_cache_delete( self::LOG_NAME, 'options' ); $log = get_option( self::LOG_NAME, [] ); // In case the DB log is corrupted. if ( ! is_array( $log ) ) { $log = []; } return $log; } } loggers/logger-interface.php 0000666 00000002364 15214176026 0012151 0 ustar 00 <?php namespace Elementor\Core\Logger\Loggers; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } interface Logger_Interface { const LEVEL_INFO = 'info'; const LEVEL_NOTICE = 'notice'; const LEVEL_WARNING = 'warning'; const LEVEL_ERROR = 'error'; const LOG_NAME = 'elementor_log'; /** * @param string $message * @param string $type * @param array $meta * * @return void */ public function log( $message, $type = self::LEVEL_INFO, $meta = [] ); /** * @param string $message * @param array $meta * * @return void */ public function info( $message, $meta = [] ); /** * @param string $message * @param array $meta * * @return void */ public function notice( $message, $meta = [] ); /** * @param string $message * @param array $meta * * @return void */ public function warning( $message, $meta = [] ); /** * @param string $message * @param array $meta * * @return void */ public function error( $message, $meta = [] ); /** * @param int $max_entries * @param bool $table use <td> in format * * @return array [ 'key' => [ 'total_count' => int, 'count' => int, 'entries' => Log_Item[] ] ] */ public function get_formatted_log_entries( $max_entries, $table = true ); } manager.php 0000666 00000012262 15214176026 0006702 0 ustar 00 <?php namespace Elementor\Core\Logger; use Elementor\Core\Base\Module as BaseModule; use Elementor\Core\Common\Modules\Ajax\Module; use Elementor\Core\Logger\Loggers\Logger_Interface; use Elementor\Core\Logger\Items\PHP; use Elementor\Core\Logger\Items\JS; use Elementor\Plugin; use Elementor\Modules\System_Info\Module as System_Info; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Manager extends BaseModule { protected $loggers = []; protected $default_logger = ''; public function get_name() { return 'log'; } public function shutdown() { $last_error = error_get_last(); if ( ! $last_error ) { return; } if ( empty( $last_error['file'] ) ) { return; } $error_path = ( wp_normalize_path( $last_error['file'] ) ); // `untrailingslashit` in order to include other plugins prefixed with elementor. $elementor_path = untrailingslashit( wp_normalize_path( ELEMENTOR_PATH ) ); if ( false === strpos( $error_path, $elementor_path ) ) { return; } $last_error['type'] = $this->get_log_type_from_php_error( $last_error['type'] ); $last_error['trace'] = true; $item = new PHP( $last_error ); $this->get_logger()->log( $item ); } public function add_system_info_report() { System_Info::add_report( 'log', [ 'file_name' => __DIR__ . '/log-reporter.php', 'class_name' => __NAMESPACE__ . '\Log_Reporter', ] ); } /** * Javascript log. * * Log Elementor errors and save them in the database. * * Fired by `wp_ajax_elementor_js_log` action. * */ public function js_log() { /** @var Module $ajax */ $ajax = Plugin::$instance->common->get_component( 'ajax' ); if ( ! $ajax->verify_request_nonce() || empty( $_POST['data'] ) ) { wp_send_json_error(); } array_walk_recursive( $_POST['data'], function( &$value ) { $value = sanitize_text_field( $value ); } ); foreach ( $_POST['data'] as $error ) { $error['type'] = Logger_Interface::LEVEL_ERROR; if ( ! empty( $error['customFields'] ) ) { $error['meta'] = $error['customFields']; } $item = new JS( $error ); $this->get_logger()->log( $item ); } wp_send_json_success(); } public function register_logger( $name, $class ) { $this->loggers[ $name ] = $class; } public function set_default_logger( $name ) { if ( ! empty( $this->loggers[ $name ] ) ) { $this->default_logger = $name; } } public function register_default_loggers() { $this->register_logger( 'db', 'Elementor\Core\Logger\Loggers\Db' ); $this->set_default_logger( 'db' ); } /** * @param string $name * * @return Logger_Interface */ public function get_logger( $name = '' ) { $this->register_loggers(); if ( empty( $name ) || ! isset( $this->loggers[ $name ] ) ) { $name = $this->default_logger; } if ( ! $this->get_component( $name ) ) { $this->add_component( $name, new $this->loggers[ $name ]() ); } return $this->get_component( $name ); } /** * @param string $message * @param array $args * * @return void */ public function log( $message, $args = [] ) { $this->get_logger()->log( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function info( $message, $args = [] ) { $this->get_logger()->info( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function notice( $message, $args = [] ) { $this->get_logger()->notice( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function warning( $message, $args = [] ) { $this->get_logger()->warning( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function error( $message, $args = [] ) { $this->get_logger()->error( $message, $args ); } private function get_log_type_from_php_error( $type ) { $error_map = [ E_CORE_ERROR => Logger_Interface::LEVEL_ERROR, E_ERROR => Logger_Interface::LEVEL_ERROR, E_USER_ERROR => Logger_Interface::LEVEL_ERROR, E_COMPILE_ERROR => Logger_Interface::LEVEL_ERROR, E_RECOVERABLE_ERROR => Logger_Interface::LEVEL_ERROR, E_PARSE => Logger_Interface::LEVEL_ERROR, E_STRICT => Logger_Interface::LEVEL_ERROR, E_WARNING => Logger_Interface::LEVEL_WARNING, E_USER_WARNING => Logger_Interface::LEVEL_WARNING, E_CORE_WARNING => Logger_Interface::LEVEL_WARNING, E_COMPILE_WARNING => Logger_Interface::LEVEL_WARNING, E_NOTICE => Logger_Interface::LEVEL_NOTICE, E_USER_NOTICE => Logger_Interface::LEVEL_NOTICE, E_DEPRECATED => Logger_Interface::LEVEL_NOTICE, E_USER_DEPRECATED => Logger_Interface::LEVEL_NOTICE, ]; return isset( $error_map[ $type ] ) ? $error_map[ $type ] : Logger_Interface::LEVEL_ERROR; } private function register_loggers() { if ( ! did_action( 'elementor/loggers/register' ) ) { do_action( 'elementor/loggers/register', $this ); } } public function __construct() { register_shutdown_function( [ $this, 'shutdown' ] ); add_action( 'admin_init', [ $this, 'add_system_info_report' ], 80 ); add_action( 'wp_ajax_elementor_js_log', [ $this, 'js_log' ] ); add_action( 'elementor/loggers/register', [ $this, 'register_default_loggers' ] ); } } class-cartflows-logger-interface.php 0000666 00000007412 15214214026 0013604 0 ustar 00 <?php /** * Logger Interface * * @version 3.0.0 * @package WooCommerce/Interface */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * WC Logger Interface * * Functions that must be defined to correctly fulfill logger API. * * @version 3.0.0 */ interface Cartflows_WC_Logger_Interface { /** * Add a log entry. * * This is not the preferred method for adding log messages. Please use log() or any one of * the level methods (debug(), info(), etc.). This method may be deprecated in the future. * * @param string $handle File handle. * @param string $message Log message. * @param string $level Log level. * * @return bool True if log was added, otherwise false. */ public function add( $handle, $message, $level = Cartflows_Log_Levels::NOTICE ); /** * Add a log entry. * * @param string $level One of the following: * 'emergency': System is unusable. * 'alert': Action must be taken immediately. * 'critical': Critical conditions. * 'error': Error conditions. * 'warning': Warning conditions. * 'notice': Normal but significant condition. * 'info': Informational messages. * 'debug': Debug-level messages. * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function log( $level, $message, $context = array() ); /** * Adds an emergency level message. * * System is unusable. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function emergency( $message, $context = array() ); /** * Adds an alert level message. * * Action must be taken immediately. * Example: Entire website down, database unavailable, etc. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function alert( $message, $context = array() ); /** * Adds a critical level message. * * Critical conditions. * Example: Application component unavailable, unexpected exception. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function critical( $message, $context = array() ); /** * Adds an error level message. * * Runtime errors that do not require immediate action but should typically be logged * and monitored. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function error( $message, $context = array() ); /** * Adds a warning level message. * * Exceptional occurrences that are not errors. * * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not * necessarily wrong. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function warning( $message, $context = array() ); /** * Adds a notice level message. * * Normal but significant events. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function notice( $message, $context = array() ); /** * Adds a info level message. * * Interesting events. * Example: User logs in, SQL logs. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function info( $message, $context = array() ); /** * Adds a debug level message. * * Detailed debug information. * * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function debug( $message, $context = array() ); } class-cartflows-log-handler-interface.php 0000666 00000001401 15214214026 0014511 0 ustar 00 <?php /** * Log Handler Interface * * @version 3.3.0 * @package WooCommerce/Interface */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * WC Log Handler Interface * * Functions that must be defined to correctly fulfill log handler API. * * @version 3.3.0 */ interface Cartflows_Log_Handler_Interface { /** * Handle a log entry. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug. * @param string $message Log message. * @param array $context Additional information for log handlers. * * @return bool False if value was not handled and true if value was handled. */ public function handle( $timestamp, $level, $message, $context ); } class-cartflows-wc-logger.php 0000666 00000021000 15214214026 0012242 0 ustar 00 <?php /** * Provides logging capabilities for debugging purposes. * * @class Cartflows_WC_Logger * @version 2.0.0 * @package WooCommerce/Classes */ defined( 'ABSPATH' ) || exit; /** * Cartflows_WC_Logger class. */ class Cartflows_WC_Logger implements Cartflows_WC_Logger_Interface { /** * Stores registered log handlers. * * @var array */ protected $handlers; /** * Minimum log level this handler will process. * * @var int Integer representation of minimum log level to handle. */ protected $threshold; /** * Constructor for the logger. * * @param array $handlers Optional. Array of log handlers. If $handlers is not provided, the filter 'woocommerce_register_log_handlers' will be used to define the handlers. If $handlers is provided, the filter will not be applied and the handlers will be used directly. * @param string $threshold Optional. Define an explicit threshold. May be configured via WC_LOG_THRESHOLD. By default, all logs will be processed. */ public function __construct( $handlers = null, $threshold = null ) { if ( null === $handlers ) { $handlers = apply_filters( 'cartflows_register_log_handlers', array() ); $default_handler = new Cartflows_Log_Handler_File(); array_push( $handlers, $default_handler ); } $register_handlers = array(); if ( ! empty( $handlers ) && is_array( $handlers ) ) { foreach ( $handlers as $handler ) { $implements = class_implements( $handler ); if ( is_object( $handler ) && is_array( $implements ) && in_array( 'Cartflows_Log_Handler_Interface', $implements, true ) ) { $register_handlers[] = $handler; } else { wc_doing_it_wrong( __METHOD__, sprintf( /* translators: 1: class name 2: Cartflows_Log_Handler_Interface */ __( 'The provided handler %1$s does not implement %2$s.', 'cartflows' ), '<code>' . esc_html( is_object( $handler ) ? get_class( $handler ) : $handler ) . '</code>', '<code>Cartflows_Log_Handler_Interface</code>' ), '3.0' ); } } } if ( null !== $threshold ) { $threshold = Cartflows_Log_Levels::get_level_severity( $threshold ); } elseif ( defined( 'WC_LOG_THRESHOLD' ) && Cartflows_Log_Levels::is_valid_level( WC_LOG_THRESHOLD ) ) { $threshold = Cartflows_Log_Levels::get_level_severity( WC_LOG_THRESHOLD ); } else { $threshold = null; } $this->handlers = $register_handlers; $this->threshold = $threshold; } /** * Determine whether to handle or ignore log. * * @param string $level emergency|alert|critical|error|warning|notice|info|debug. * @return bool True if the log should be handled. */ protected function should_handle( $level ) { if ( null === $this->threshold ) { return true; } return $this->threshold <= Cartflows_Log_Levels::get_level_severity( $level ); } /** * Add a log entry. * * This is not the preferred method for adding log messages. Please use log() or any one of * the level methods (debug(), info(), etc.). This method may be deprecated in the future. * * @param string $handle File handle. * @param string $message Message to log. * @param string $level Logging level. * @return bool */ public function add( $handle, $message, $level = Cartflows_Log_Levels::NOTICE ) { $message = apply_filters( 'cartflows_logger_add_message', $message, $handle ); $this->log( $level, $message, array( 'source' => $handle, '_legacy' => true, ) ); wc_do_deprecated_action( 'cartflows_log_add', array( $handle, $message ), '3.0', 'This action has been deprecated with no alternative.' ); return true; } /** * Add a log entry. * * @param string $level One of the following: * 'emergency': System is unusable. * 'alert': Action must be taken immediately. * 'critical': Critical conditions. * 'error': Error conditions. * 'warning': Warning conditions. * 'notice': Normal but significant condition. * 'info': Informational messages. * 'debug': Debug-level messages. * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. */ public function log( $level, $message, $context = array() ) { if ( ! Cartflows_Log_Levels::is_valid_level( $level ) ) { /* translators: 1: Cartflows_WC_Logger::log 2: level */ wc_doing_it_wrong( __METHOD__, sprintf( __( '%1$s was called with an invalid level "%2$s".', 'cartflows' ), '<code>Cartflows_WC_Logger::log</code>', $level ), '3.0' ); } if ( $this->should_handle( $level ) ) { $timestamp = time(); $message = apply_filters( 'cartflows_logger_log_message', $message, $level, $context ); foreach ( $this->handlers as $handler ) { $handler->handle( $timestamp, $level, $message, $context ); } } } /** * Adds an emergency level message. * * System is unusable. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function emergency( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::EMERGENCY, $message, $context ); } /** * Adds an alert level message. * * Action must be taken immediately. * Example: Entire website down, database unavailable, etc. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function alert( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::ALERT, $message, $context ); } /** * Adds a critical level message. * * Critical conditions. * Example: Application component unavailable, unexpected exception. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function critical( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::CRITICAL, $message, $context ); } /** * Adds an error level message. * * Runtime errors that do not require immediate action but should typically be logged * and monitored. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function error( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::ERROR, $message, $context ); } /** * Adds a warning level message. * * Exceptional occurrences that are not errors. * * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not * necessarily wrong. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function warning( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::WARNING, $message, $context ); } /** * Adds a notice level message. * * Normal but significant events. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function notice( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::NOTICE, $message, $context ); } /** * Adds a info level message. * * Interesting events. * Example: User logs in, SQL logs. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function info( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::INFO, $message, $context ); } /** * Adds a debug level message. * * Detailed debug information. * * @see Cartflows_WC_Logger::log * * @param string $message Message to log. * @param array $context Log context. */ public function debug( $message, $context = array() ) { $this->log( Cartflows_Log_Levels::DEBUG, $message, $context ); } /** * Clear entries for a chosen file/source. * * @param string $source Source/handle to clear. * @return bool */ public function clear( $source = '' ) { if ( ! $source ) { return false; } foreach ( $this->handlers as $handler ) { if ( is_callable( array( $handler, 'clear' ) ) ) { $handler->clear( $source ); } } return true; } /** * Clear all logs older than a defined number of days. Defaults to 30 days. * * @since 3.4.0 */ public function clear_expired_logs() { $days = absint( apply_filters( 'cartflows_logger_days_to_retain_logs', 30 ) ); $timestamp = strtotime( "-{$days} days" ); foreach ( $this->handlers as $handler ) { if ( is_callable( array( $handler, 'delete_logs_before_timestamp' ) ) ) { $handler->delete_logs_before_timestamp( $timestamp ); } } } } class-cartflows-log-handler-file.php 0000666 00000026764 15214214026 0013513 0 ustar 00 <?php /** * Class Cartflows_Log_Handler_File file. * * @package WooCommerce\Log Handlers */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Handles log entries by writing to a file. * * @class Cartflows_Log_Handler_File * @version 1.0.0 * @package WooCommerce/Classes/Log_Handlers */ class Cartflows_Log_Handler_File extends Cartflows_Log_Handler { /** * Stores open file handles. * * @var array */ protected $handles = array(); /** * File size limit for log files in bytes. * * @var int */ protected $log_size_limit; /** * Cache logs that could not be written. * * If a log is written too early in the request, pluggable functions may be unavailable. These * logs will be cached and written on 'plugins_loaded' action. * * @var array */ protected $cached_logs = array(); /** * Constructor for the logger. * * @param int $log_size_limit Optional. Size limit for log files. Default 5mb. */ public function __construct( $log_size_limit = null ) { if ( null === $log_size_limit ) { $log_size_limit = 5 * 1024 * 1024; } $this->log_size_limit = apply_filters( 'cartflows_log_file_size_limit', $log_size_limit ); add_action( 'plugins_loaded', array( $this, 'write_cached_logs' ) ); } /** * Destructor. * * Cleans up open file handles. */ public function __destruct() { foreach ( $this->handles as $handle ) { if ( is_resource( $handle ) ) { fclose( $handle ); // @codingStandardsIgnoreLine. } } } /** * Handle a log entry. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug. * @param string $message Log message. * @param array $context { * Additional information for log handlers. * * @type string $source Optional. Determines log file to write to. Default 'log'. * @type bool $_legacy Optional. Default false. True to use outdated log format * originally used in deprecated Cartflows_WC_Logger::add calls. * } * * @return bool False if value was not handled and true if value was handled. */ public function handle( $timestamp, $level, $message, $context ) { if ( isset( $context['source'] ) && $context['source'] ) { $handle = $context['source']; } else { $handle = 'log'; } $entry = self::format_entry( $timestamp, $level, $message, $context ); return $this->add( $entry, $handle ); } /** * Builds a log entry text from timestamp, level and message. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug. * @param string $message Log message. * @param array $context Additional information for log handlers. * * @return string Formatted log entry. */ protected static function format_entry( $timestamp, $level, $message, $context ) { if ( isset( $context['_legacy'] ) && true === $context['_legacy'] ) { if ( isset( $context['source'] ) && $context['source'] ) { $handle = $context['source']; } else { $handle = 'log'; } $message = apply_filters( 'cartflows_logger_add_message', $message, $handle ); $time = date_i18n( 'm-d-Y @ H:i:s' ); $entry = "{$time} - {$message}"; } else { $entry = parent::format_entry( $timestamp, $level, $message, $context ); } return $entry; } /** * Open log file for writing. * * @param string $handle Log handle. * @param string $mode Optional. File mode. Default 'a'. * @return bool Success. */ protected function open( $handle, $mode = 'a' ) { if ( $this->is_open( $handle ) ) { return true; } $file = self::get_log_file_path( $handle ); if ( $file ) { if ( ! file_exists( $file ) ) { $temphandle = @fopen( $file, 'w+' ); // @codingStandardsIgnoreLine. @fclose( $temphandle ); // @codingStandardsIgnoreLine. if ( defined( 'FS_CHMOD_FILE' ) ) { @chmod( $file, FS_CHMOD_FILE ); // @codingStandardsIgnoreLine. } } $resource = @fopen( $file, $mode ); // @codingStandardsIgnoreLine. if ( $resource ) { $this->handles[ $handle ] = $resource; return true; } } return false; } /** * Check if a handle is open. * * @param string $handle Log handle. * @return bool True if $handle is open. */ protected function is_open( $handle ) { return array_key_exists( $handle, $this->handles ) && is_resource( $this->handles[ $handle ] ); } /** * Close a handle. * * @param string $handle Log handle. * @return bool success */ protected function close( $handle ) { $result = false; if ( $this->is_open( $handle ) ) { $result = fclose( $this->handles[ $handle ] ); // @codingStandardsIgnoreLine. unset( $this->handles[ $handle ] ); } return $result; } /** * Add a log entry to chosen file. * * @param string $entry Log entry text. * @param string $handle Log entry handle. * * @return bool True if write was successful. */ protected function add( $entry, $handle ) { $result = false; if ( $this->should_rotate( $handle ) ) { $this->log_rotate( $handle ); } if ( $this->open( $handle ) && is_resource( $this->handles[ $handle ] ) ) { $result = fwrite( $this->handles[ $handle ], $entry . PHP_EOL ); // @codingStandardsIgnoreLine. } else { $this->cache_log( $entry, $handle ); } return false !== $result; } /** * Clear entries from chosen file. * * @param string $handle Log handle. * * @return bool */ public function clear( $handle ) { $result = false; // Close the file if it's already open. $this->close( $handle ); /** * $this->open( $handle, 'w' ) == Open the file for writing only. Place the file pointer at * the beginning of the file, and truncate the file to zero length. */ if ( $this->open( $handle, 'w' ) && is_resource( $this->handles[ $handle ] ) ) { $result = true; } do_action( 'cartflows_log_clear', $handle ); return $result; } /** * Remove/delete the chosen file. * * @param string $handle Log handle. * * @return bool */ public function remove( $handle ) { $removed = false; $logs = $this->get_log_files(); $handle = sanitize_title( $handle ); if ( isset( $logs[ $handle ] ) && $logs[ $handle ] ) { $file = realpath( trailingslashit( CARTFLOWS_LOG_DIR ) . $logs[ $handle ] ); if ( 0 === stripos( $file, realpath( trailingslashit( CARTFLOWS_LOG_DIR ) ) ) && is_file( $file ) && is_writable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable $this->close( $file ); // Close first to be certain no processes keep it alive after it is unlinked. $removed = unlink( $file ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_unlink } do_action( 'cartflows_log_remove', $handle, $removed ); } return $removed; } /** * Check if log file should be rotated. * * Compares the size of the log file to determine whether it is over the size limit. * * @param string $handle Log handle. * @return bool True if if should be rotated. */ protected function should_rotate( $handle ) { $file = self::get_log_file_path( $handle ); if ( $file ) { if ( $this->is_open( $handle ) ) { $file_stat = fstat( $this->handles[ $handle ] ); return $file_stat['size'] > $this->log_size_limit; } elseif ( file_exists( $file ) ) { return filesize( $file ) > $this->log_size_limit; } else { return false; } } else { return false; } } /** * Rotate log files. * * Logs are rotated by prepending '.x' to the '.log' suffix. * The current log plus 10 historical logs are maintained. * For example: * base.9.log -> [ REMOVED ] * base.8.log -> base.9.log * ... * base.0.log -> base.1.log * base.log -> base.0.log * * @param string $handle Log handle. */ protected function log_rotate( $handle ) { for ( $i = 8; $i >= 0; $i-- ) { $this->increment_log_infix( $handle, $i ); } $this->increment_log_infix( $handle ); } /** * Increment a log file suffix. * * @param string $handle Log handle. * @param null|int $number Optional. Default null. Log suffix number to be incremented. * @return bool True if increment was successful, otherwise false. */ protected function increment_log_infix( $handle, $number = null ) { if ( null === $number ) { $suffix = ''; $next_suffix = '.0'; } else { $suffix = '.' . $number; $next_suffix = '.' . ( $number + 1 ); } $rename_from = self::get_log_file_path( "{$handle}{$suffix}" ); $rename_to = self::get_log_file_path( "{$handle}{$next_suffix}" ); if ( $this->is_open( $rename_from ) ) { $this->close( $rename_from ); } if ( is_writable( $rename_from ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable return rename( $rename_from, $rename_to ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_rename } else { return false; } } /** * Get a log file path. * * @param string $handle Log name. * @return bool|string The log file path or false if path cannot be determined. */ public static function get_log_file_path( $handle ) { if ( function_exists( 'wp_hash' ) ) { return trailingslashit( CARTFLOWS_LOG_DIR ) . self::get_log_file_name( $handle ); } else { wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'cartflows' ), '3.0' ); return false; } } /** * Get a log file name. * * File names consist of the handle, followed by the date, followed by a hash, .log. * * @since 3.3 * @param string $handle Log name. * @return bool|string The log file name or false if cannot be determined. */ public static function get_log_file_name( $handle ) { if ( function_exists( 'wp_hash' ) ) { $date_suffix = gmdate( 'Y-m-d', time() ); $hash_suffix = wp_hash( $handle ); return sanitize_file_name( implode( '-', array( $handle, $date_suffix, $hash_suffix ) ) . '.log' ); } else { wc_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'cartflows' ), '3.3' ); return false; } } /** * Cache log to write later. * * @param string $entry Log entry text. * @param string $handle Log entry handle. */ protected function cache_log( $entry, $handle ) { $this->cached_logs[] = array( 'entry' => $entry, 'handle' => $handle, ); } /** * Write cached logs. */ public function write_cached_logs() { foreach ( $this->cached_logs as $log ) { $this->add( $log['entry'], $log['handle'] ); } } /** * Delete all logs older than a defined timestamp. * * @since 3.4.0 * @param integer $timestamp Timestamp to delete logs before. */ public static function delete_logs_before_timestamp( $timestamp = 0 ) { if ( ! $timestamp ) { return; } $log_files = self::get_log_files(); foreach ( $log_files as $log_file ) { $last_modified = filemtime( trailingslashit( CARTFLOWS_LOG_DIR ) . $log_file ); if ( $last_modified < $timestamp ) { @unlink( trailingslashit( CARTFLOWS_LOG_DIR ) . $log_file ); // @codingStandardsIgnoreLine. } } } /** * Get all log files in the log directory. * * @since 3.4.0 * @return array */ public static function get_log_files() { $files = @scandir( CARTFLOWS_LOG_DIR ); // @codingStandardsIgnoreLine. $result = array(); if ( ! empty( $files ) ) { foreach ( $files as $key => $value ) { if ( ! in_array( $value, array( '.', '..' ), true ) ) { if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) { $result[ sanitize_title( $value ) ] = $value; } } } } return $result; } } class-cartflows-log-handler.php 0000666 00000002637 15214214026 0012567 0 ustar 00 <?php /** * Log handling functionality. * * @class Cartflows_Log_Handler * @package WooCommerce/Abstracts */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Abstract WC Log Handler Class * * @version 1.0.0 * @package WooCommerce/Abstracts */ abstract class Cartflows_Log_Handler implements Cartflows_Log_Handler_Interface { /** * Formats a timestamp for use in log messages. * * @param int $timestamp Log timestamp. * @return string Formatted time for use in log entry. */ protected static function format_time( $timestamp ) { return gmdate( 'c', $timestamp ); } /** * Builds a log entry text from level, timestamp and message. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug. * @param string $message Log message. * @param array $context Additional information for log handlers. * * @return string Formatted log entry. */ protected static function format_entry( $timestamp, $level, $message, $context ) { $time_string = self::format_time( $timestamp ); $level_string = strtoupper( $level ); $entry = "{$time_string} {$level_string} {$message}"; return apply_filters( 'cartflows_format_log_entry', $entry, array( 'timestamp' => $timestamp, 'level' => $level, 'message' => $message, 'context' => $context, ) ); } } class-cartflows-log-levels.php 0000666 00000005057 15214214026 0012443 0 ustar 00 <?php /** * Standard log levels * * @version 3.2.0 * @package WooCommerce/Classes */ defined( 'ABSPATH' ) || exit; /** * Log levels class. */ abstract class Cartflows_Log_Levels { /** * Log Levels * * Description of levels: * 'emergency': System is unusable. * 'alert': Action must be taken immediately. * 'critical': Critical conditions. * 'error': Error conditions. * 'warning': Warning conditions. * 'notice': Normal but significant condition. * 'info': Informational messages. * 'debug': Debug-level messages. * * @see @link {https://tools.ietf.org/html/rfc5424} */ const EMERGENCY = 'emergency'; const ALERT = 'alert'; const CRITICAL = 'critical'; const ERROR = 'error'; const WARNING = 'warning'; const NOTICE = 'notice'; const INFO = 'info'; const DEBUG = 'debug'; /** * Level strings mapped to integer severity. * * @var array */ protected static $level_to_severity = array( self::EMERGENCY => 800, self::ALERT => 700, self::CRITICAL => 600, self::ERROR => 500, self::WARNING => 400, self::NOTICE => 300, self::INFO => 200, self::DEBUG => 100, ); /** * Severity integers mapped to level strings. * * This is the inverse of $level_severity. * * @var array */ protected static $severity_to_level = array( 800 => self::EMERGENCY, 700 => self::ALERT, 600 => self::CRITICAL, 500 => self::ERROR, 400 => self::WARNING, 300 => self::NOTICE, 200 => self::INFO, 100 => self::DEBUG, ); /** * Validate a level string. * * @param string $level Log level. * @return bool True if $level is a valid level. */ public static function is_valid_level( $level ) { return array_key_exists( strtolower( $level ), self::$level_to_severity ); } /** * Translate level string to integer. * * @param string $level Log level, options: emergency|alert|critical|error|warning|notice|info|debug. * @return int 100 (debug) - 800 (emergency) or 0 if not recognized */ public static function get_level_severity( $level ) { return self::is_valid_level( $level ) ? self::$level_to_severity[ strtolower( $level ) ] : 0; } /** * Translate severity integer to level string. * * @param int $severity Serevity level. * @return bool|string False if not recognized. Otherwise string representation of level. */ public static function get_severity_level( $severity ) { if ( ! array_key_exists( $severity, self::$severity_to_level ) ) { return false; } return self::$severity_to_level[ $severity ]; } }
| ver. 1.4 |
Github
|
.
| PHP 7.0.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings