Skip to content
Snippets Groups Projects
Select Git revision
  • 2d5cb9e473bb8ede4fa2290b74f03115aba275f5
  • master default protected
  • feat/message-handling
  • feat/request-id
  • 1.13.2
  • 1.13.1
  • 1.13.0
  • 1.12.1
  • 1.12.0
  • 1.11.0
  • 1.11.0-beta2
  • 1.11.0-beta1
  • 1.10.2
  • 1.10.1
  • 1.10.0
  • 1.9.0
  • 1.8.0
  • 1.7.4
  • 1.7.3
  • 1.7.2
  • 1.7.1
  • 1.7.0
  • 1.6.2
  • 1.6.2-beta2
24 results

wpdesk-logger.php

Blame
  • wpdesk-logger.php 3.14 KiB
    <?php
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    if ( ! class_exists( 'WPDesk_Logger' ) ) {
    	/**
    	 * @deprecated Only for backward compatibility. Please use injected Logger compatible with PSR
    	 */
    	class WPDesk_Logger {
    
    		/** @var \Psr\Log\LoggerInterface */
    		static $logger;
    
    		const EMERGENCY = 'emergency';
    		const ALERT = 'alert';
    		const CRITICAL = 'critical';
    		const ERROR = 'error';
    		const WARNING = 'warning';
    		const NOTICE = 'notice';
    		const INFO = 'info';
    		const DEBUG = 'debug';
    
    		public function __construct() {
    			if (!self::$logger) {
    				$loggerFactroy = new \WPDesk\Logger\WPDeskLoggerFactory();
    				self::$logger = $loggerFactroy->createWPDeskLogger();
    			}
    		}
    
    		/**
    		 * Level strings mapped to integer severity.
    		 *
    		 * @var array
    		 */
    		protected $level_to_severity = [
    			self::EMERGENCY => 800,
    			self::ALERT     => 700,
    			self::CRITICAL  => 600,
    			self::ERROR     => 500,
    			self::WARNING   => 400,
    			self::NOTICE    => 300,
    			self::INFO      => 200,
    			self::DEBUG     => 100,
    		];
    
    		/**
    		 * Attach hooks
    		 *
    		 * @return void
    		 */
    		public function attach_hooks() {
    			add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
    			add_filter( 'wpdesk_logger_level_options', [ $this, 'wpdesk_logger_level_options' ] );
    		}
    
    		public function plugins_loaded() {
    			if ( defined( 'WC_VERSION' ) ) {
    				if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
    					add_action( 'wpdesk_log', [ $this, 'wpdesk_log' ], 10, 4 );
    				} else {
    					add_action( 'wpdesk_log', [ $this, 'wpdesk_log_30' ], 10, 4 );
    				}
    			}
    		}
    
    		public function wpdesk_logger_level_options( array $options ) {
    			return [
    				'disabled'  => __( 'Disabled', 'wp-logs' ),