-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[debug] [logging] Automatically turn off fs_debug_mode
after 24 hours
#691
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra greately done 👏 ... I think your logic is sound. Please see my suggestion for a little refactoring to make the main class a little bit slim and also code convention fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @DanieleAlessandra nicely done 👏 ... Please see my few comments. Also kindly do a self review and fix the indentation glitches. We are getting close to merging this.
2977f06
to
f34b38f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greatly done @DanieleAlessandra 👍 Please see my two comments and we can merge this.
Also don't forget to rebase on develop
and bump pre-release version of start.php
includes/class-fs-storage.php
Outdated
/** | ||
* @var bool|int | ||
*/ | ||
public $install_timestamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra would it also work if you just add a @property bool|int $install_timestamp
in the PHP doc block, instead of this change?
The reason I am asking is, let's not make changes to the existing system, unless needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it will work, I try...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great 👏
require.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert indentation changes please.
f34b38f
to
2f3ddee
Compare
includes/class-freemius.php
Outdated
@@ -20815,7 +20448,7 @@ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expir | |||
* | |||
* @return bool|FS_Plugin_Tag | |||
*/ | |||
function get_update( $plugin_id = false, $flush = true, $expiration = FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION, $newer_than = false ) { | |||
function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra rebase glitch.. Please use $expiration = FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION
includes/class-freemius.php
Outdated
*/ | ||
$was_license_expired_before_sync = $this->_license->is_expired(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra rebase glitch, please revert
includes/class-freemius.php
Outdated
@@ -22484,7 +22115,7 @@ private function check_updates( | |||
$background = false, | |||
$plugin_id = false, | |||
$flush = true, | |||
$expiration = FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION, | |||
$expiration = WP_FS__TIME_24_HOURS_IN_SEC, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra rebase glitch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @DanieleAlessandra, nicely done. But it looks like I (accidentally) stumbled upon a race-condition or bad-state like issue in the class-fs-logger that can bite us.
Please see this
To reproduce, I have
- Changed
wp_schedule_single_event( time() + 24 * HOUR_IN_SECONDS, 'fs_debug_turn_off_logging_hook' );
towp_schedule_single_event( time() + 5, 'fs_debug_turn_off_logging_hook' );
- Turned on
WP_DEBUG
- Enabled the Freemius debugging.
- Waited 5 sec and refreshed
- The error pops up sometimes and sometimes it doesn't.
I think the issue is in class-fs-logger and the static variable $_isStorageLoggingOn
which is not cleared/updated after calling _set_storage_logging
. Kindly take a look. Thanks.
6b0a528
to
aad603c
Compare
includes/class-fs-logger.php
Outdated
/** | ||
* @var bool | ||
*/ | ||
public static $ON = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra I think we are mixing two things here :)
We have the function _set_storage_logging
which only deals with DB related storage. So making it off
shouldn't really turn off regular logging.
For calling $wpdb->insert
when we have just turned off the logging
We need to update the already existing $_isStorageLoggingOn
static variable inside the _set_storage_logging
. Something like
public static function _set_storage_logging( $is_on = true ) {
// .. existing code
self::$_isStorageLoggingOn = $is_on;
}
and that's it. I think this will work just fine.
Out of sync DB creation issue
I see you've made adjustment in the creation statement with CREATE TABLE IF NOT EXISTS
. I propose we do it like this:
- Drop table if exists.
- Then create the table.
I think this way when the logging is turned on we are 100% sure to get the table schema we are after. Since we are dropping table anyway when turning off, I think this approach is fine.
So kindly see if the above suggestion would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the indentation glitch and one conceptual thing @DanieleAlessandra
includes/class-fs-logger.php
Outdated
@@ -125,6 +128,14 @@ function on() { | |||
self::hook_footer(); | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation glitch
includes/class-fs-logger.php
Outdated
@@ -240,6 +251,9 @@ function api_error( $api_result, $wrapper = false ) { | |||
} | |||
|
|||
function entrance( $message = '', $wrapper = false ) { | |||
if ( ! $this->is_on() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation glitch
includes/class-fs-logger.php
Outdated
@@ -240,6 +251,9 @@ function api_error( $api_result, $wrapper = false ) { | |||
} | |||
|
|||
function entrance( $message = '', $wrapper = false ) { | |||
if ( ! $this->is_on() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be needed since the _log
is already bailing. If you want to be more memory/compute optimistic, then we need to have this check for every public log related function, but that isn't needed IMO.
includes/class-fs-logger.php
Outdated
@@ -320,6 +334,11 @@ public static function _set_storage_logging( $is_on = true ) { | |||
|
|||
$table = "{$wpdb->prefix}fs_logger"; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation glitch, also please fix for the rest of the file.
@@ -329,7 +348,7 @@ public static function _set_storage_logging( $is_on = true ) { | |||
* | |||
* @link https://core.trac.wordpress.org/ticket/2695 | |||
*/ | |||
$result = $wpdb->query( "CREATE TABLE {$table} ( | |||
$result = $wpdb->query( "CREATE TABLE IF NOT EXISTS {$table} ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this IF NOT EXISTS
needed now that we are dropping the table anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table could exist if it was created with a previous version and never deleted
includes/class-fs-logger.php
Outdated
/** | ||
* Since logging table does not exist anymore, we need to turn off all instances | ||
*/ | ||
foreach ( self::$LOGGERS as $logger ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this isn't needed. Because we have just turned off "DB" storage of the log. The actual log happens with the constant WP_FS__DEBUG_SDK
. So if DB storage is turned off, let there still be memory logging within the _log
and it will show up in the JavaScript console. The only fix needed is turning off the $_isStorageLoggingOn
in line 385 like you did :)
includes/class-fs-logger.php
Outdated
* | ||
* @return void | ||
*/ | ||
public function off() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method won't be needed anymore (please see my suggestion below). Also just a code convention thingy, we add a blank line after a function/method declaration.
} | ||
|
||
// Turn on/off storage logging. | ||
FS_Logger::_set_storage_logging( ( 1 == $is_on ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra please see that you are already setting storage login from the _turn_off_debug_mode
or the _turn_on_debug_mode
above (line 284). So I feel this call is redundant.
…, moved debug logic from Freemius to new FS_DebugManager class, fix a bug about logging attempt to DB when table does not exist.
787bd33
to
b7e311d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @DanieleAlessandra 👏
When the user activates debugging a single event cron starts:
wp_schedule_single_event(time() + 24 * HOUR_IN_SECONDS, 'fs_debug_turn_off_logging_hook');
When the user deactivates debuggong this cron is unscheduled:
wp_unschedule_event($timestamp, 'fs_debug_turn_off_logging_hook');
If the event happens, the option is set to off:
add_action('fs_debug_turn_off_logging_hook', array( self::class, '_turn_off_debug_mode' ) );
Also, in the debug page I added a countdown timer, so the user is informed about the fact that debugging will be disabled automatically.
![image](https://private-user-images.githubusercontent.com/4690419/311800333-ab43a5c9-c653-4d11-b0ba-bd6d725d24f2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NjM3MzMsIm5iZiI6MTczOTY2MzQzMywicGF0aCI6Ii80NjkwNDE5LzMxMTgwMDMzMy1hYjQzYTVjOS1jNjUzLTRkMTEtYjBiYS1iZDZkNzI1ZDI0ZjIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMjM1MDMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZWMxMGMzMTdlM2YyYjc3MmVhY2M5YjkxYzViZDg4N2M2OTI1ZDllM2M0YWI2M2RkM2I0NDRkZjBjZDExMTJhYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.ZCKT6fQxqCfaG0s0eDn7A-KMopFUcBB_yYiGFsLAbn8)