Plugin Directory

Changeset 1496912


Ignore:
Timestamp:
09/16/2016 12:46:35 PM (9 years ago)
Author:
Double Eye
Message:

Added configuration for logging

Location:
the-loyalty-box-woocommerce-rewards-program/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • the-loyalty-box-woocommerce-rewards-program/trunk/includes/loyaltybox.inc.php

    r1182491 r1496912  
    430430        return $result;
    431431    }
    432    
    433     /**
    434     * logError.
    435     *
    436     * A method to log errors information to disk
    437     *
    438     * @version 1.0.0
    439     *
    440     * @author Double Eye
    441     *
    442     * @since 1.0.0
    443     * @access public
    444     *
    445     * @param      $info
    446     * @param bool $first_line
    447     *
    448     * @static
    449     */
     432
     433    /**
     434     * logError.
     435     *
     436     * A method to log errors information to disk
     437     *
     438     * @version 1.0.0
     439     *
     440     * @author Double Eye
     441     *
     442     * @since 1.0.0
     443     * @access public
     444     *
     445     * @param      $info
     446     * @param bool $first_line
     447     *
     448     * @static
     449     */
    450450    public static function logError($info, $first_line = false)
    451451    {
     452        $option_name = 'wc_settings_tab_loyaltybox_error_logging';
     453        $check_switch = Loyaltybox::check_if_errors_enabled($option_name);
    452454        $log = date('Y-m-d H:i:s.uP')." => ".$info.PHP_EOL;
    453455        if ($first_line) {
    454456            $log = PHP_EOL.PHP_EOL.$log;
    455457        }
    456         file_put_contents(LOYALTYBOX_ERROR_LOG, $log, FILE_APPEND);
     458        if($check_switch == true){
     459            file_put_contents(LOYALTYBOX_ERROR_LOG, $log, FILE_APPEND);
     460        }
    457461    }
    458462   
     
    480484    public static function makeRequest($paramArray = null, $methodCall = null, $getDetails = FALSE)
    481485    {
     486        $option_name = 'wc_settings_tab_loyaltybox_request_logging';
     487        $check_switch = Loyaltybox::check_if_errors_enabled($option_name);
    482488        $url = self::$endpoint;
    483489        $time_start = microtime(true);
     
    501507                    @ob_clean();
    502508                    $request = $client->__getLastRequest();
    503                     file_put_contents(LOYALTYBOX_REQUEST_LOG, " ".$methodCall."-".date('Y-m-d H:i:s.uP')." ".PHP_EOL." ", FILE_APPEND);
    504                     file_put_contents(LOYALTYBOX_REQUEST_LOG, $request, FILE_APPEND);
    505                     file_put_contents(LOYALTYBOX_REQUEST_LOG, $resultContent, FILE_APPEND);
     509                    if($check_switch == true){
     510                        file_put_contents(LOYALTYBOX_REQUEST_LOG, " ".$methodCall."-".date('Y-m-d H:i:s.uP')." ".PHP_EOL." ", FILE_APPEND);
     511                        file_put_contents(LOYALTYBOX_REQUEST_LOG, $request, FILE_APPEND);
     512                        file_put_contents(LOYALTYBOX_REQUEST_LOG, $resultContent, FILE_APPEND);
     513                    }
    506514                }
    507515                if ($getDetails) {
     
    525533        }
    526534    }
     535
     536    /**
     537     * On_off_for_error_reporting
     538     *
     539     * A method to check if the user has enabled error reporting
     540     *
     541     * @version 1.0.0
     542     *
     543     * @author Double Eye
     544     *
     545     * @since 1.0.0
     546     * @access public
     547     *
     548     * @param $option_name
     549     *
     550     * @static
     551     */
     552    public static function check_if_errors_enabled($option_name)
     553    {
     554        global $wpdb;
     555        $values = get_transient( 'special_query_results' );
     556        if ( false === $values ) {
     557            // If it wasn't there, then regenerate the data and save the transient
     558            $special_query_results = $wpdb->get_results( "SELECT * FROM wp_options WHERE option_name = '$option_name'", OBJECT );
     559            set_transient( 'special_query_results', $special_query_results, HOUR_IN_SECONDS );
     560            $values = get_transient( 'special_query_results' );
     561        }
     562        if($values[0]->option_value == 'yes'){
     563            return true;
     564        } else {
     565            return false;
     566        }
     567    }
     568
    527569   
    528570    /**
  • the-loyalty-box-woocommerce-rewards-program/trunk/includes/wc-loyaltybox-settings.php

    r1169142 r1496912  
    253253                'id' => 'wc_settings_tab_loyaltybox_section_end',
    254254            ),
     255            'request_logging' => array(
     256                'name' => __('Loyaltybox Log Files', 'woocommerce-settings-tab-loyaltybox'),
     257                'type' => 'checkbox',
     258                'default' => 'no',
     259                'show_if_checked' => 'option',
     260                'desc' => __( 'Request logging', 'woocommerce-settings-tab-demo' ),
     261                'id' => 'wc_settings_tab_loyaltybox_request_logging',
     262            ),
     263            'error_logging' => array(
     264                'type' => 'checkbox',
     265                'default' => 'no',
     266                'show_if_checked' => 'option',
     267                'desc' => __( 'Error logging', 'woocommerce-settings-tab-demo' ),
     268                'id' => 'wc_settings_tab_loyaltybox_error_logging',
     269            ),
     270            'plugin_logging' => array(
     271                'type' => 'checkbox',
     272                'default' => 'no',
     273                'show_if_checked' => 'option',
     274                'desc' => __( 'Plugin logging', 'woocommerce-settings-tab-demo' ),
     275                'id' => 'wc_settings_tab_loyaltybox_plugin_logging',
     276            ),
    255277        );
    256278
  • the-loyalty-box-woocommerce-rewards-program/trunk/readme.txt

    r1468297 r1496912  
    5252== Changelog ==
    5353
     54= 1.03 =
     55* Added configuration for logging
     56
    5457= 1.02 =
    5558* Tested with WordPress 4.5.3 and WooCommerce 2.6.4
     
    6063== Upgrade Notice ==
    6164
     65= 1.03 =
     66* Added configuration for logging
     67
    6268= 1.02 =
    6369* Tested with WordPress 4.5.3 and WooCommerce 2.6.4
Note: See TracChangeset for help on using the changeset viewer.