Skip to content

Commit 65a894d

Browse files
committed
improve the logging to use GF debug logging
1 parent 15b10a8 commit 65a894d

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/shared/class-global-license-key-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function ( $a, $b ) {
110110
if ( file_exists( $hub_ajax_file ) ) {
111111
require_once $hub_ajax_file;
112112
if ( class_exists( '\GravityWP\Shared\Hub_Ajax' ) ) {
113-
\GravityWP\Shared\Hub_Ajax::init();
113+
\GravityWP\Shared\Hub_Ajax::init( $last['addon_class'] );
114114
}
115115
}
116116

src/shared/class-hub-ajax.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ class Hub_Ajax {
2121

2222
private static $registered = false;
2323

24-
public static function init() {
24+
private static $addon_class = '';
25+
26+
public static function init( $gwp_addon_class = '' ) {
27+
self::$addon_class = (string) $gwp_addon_class;
28+
2529
if ( self::$registered ) {
2630
return;
2731
}
@@ -458,13 +462,37 @@ private static function fetch_wporg_download_link( $wporg_slug ) {
458462
return (string) $api->download_link;
459463
}
460464

461-
/** Write a diagnostic line to wp-content/debug.log (always — short lines). */
465+
/** Write a diagnostic line through the Gravity Forms add-on logger. */
462466
private static function log( $msg, $context = array() ) {
467+
if ( '' === self::$addon_class || ! class_exists( self::$addon_class ) || ! method_exists( self::$addon_class, 'get_instance' ) ) {
468+
return;
469+
}
470+
471+
$addon = call_user_func( array( self::$addon_class, 'get_instance' ) );
472+
if ( ! is_object( $addon ) || ! method_exists( $addon, 'log_debug' ) ) {
473+
return;
474+
}
475+
463476
$line = '[GWP_HUB_AJAX] ' . $msg;
464477
if ( ! empty( $context ) ) {
465-
$line .= ' ' . wp_json_encode( $context );
478+
$line .= ' ' . wp_json_encode( self::redact_log_context( $context ) );
466479
}
467-
error_log( $line );
480+
$addon->log_debug( $line );
481+
}
482+
483+
/** Redact signed/sensitive package URLs from log context. */
484+
private static function redact_log_context( $context ) {
485+
if ( is_array( $context ) ) {
486+
foreach ( $context as $key => $value ) {
487+
if ( in_array( $key, array( 'package', 'download_link' ), true ) ) {
488+
$context[ $key ] = '[redacted]';
489+
continue;
490+
}
491+
$context[ $key ] = self::redact_log_context( $value );
492+
}
493+
}
494+
495+
return $context;
468496
}
469497

470498
/** Flatten a WP_Error to a single readable line including data + child errors. */

0 commit comments

Comments
 (0)