@@ -350,90 +350,124 @@ protected function get_services_items() {
350
350
}
351
351
352
352
/**
353
- * Gets the last 10 lines from the WooCommerce Services log, if it exists
353
+ * Gets the last 10 lines from the WooCommerce Services log by feature , if it exists
354
354
*/
355
- protected function get_debug_log_data () {
356
- $ data = new stdClass ;
357
- $ data ->key = '' ;
358
- $ data ->file = '' ;
355
+ protected function get_debug_log_data ( $ feature = '' ) {
356
+ $ data = new stdClass ;
357
+ $ data ->key = '' ;
358
+ $ data ->file = null ;
359
359
$ data ->tail = array ();
360
360
361
- if ( method_exists ( 'WC_Admin_Status ' , 'scan_log_files ' ) ) {
362
- $ logs = WC_Admin_Status::scan_log_files ();
363
- $ latest_file_date = 0 ;
364
- $ file = null ;
365
- $ key = null ;
366
-
367
- foreach ( $ logs as $ log_key => $ log_file ) {
368
- $ log_file = WC_LOG_DIR . $ log_file ;
369
- $ file_date = filemtime ( $ log_file );
370
- if ( 'wc-services- ' === substr ( $ log_key , 0 , 12 ) && $ latest_file_date < $ file_date ) {
371
- $ latest_file_date = $ file_date ;
372
- $ file = $ log_file ;
373
- $ key = $ log_key ;
374
- }
361
+ if ( ! method_exists ( 'WC_Admin_Status ' , 'scan_log_files ' ) ) {
362
+ return $ data ;
363
+ }
364
+
365
+ $ log_prefix = 'wc\-services ' ;
366
+
367
+ if ( ! empty ( $ feature ) ) {
368
+ $ log_prefix .= '\- ' . $ feature ;
369
+ }
370
+
371
+ $ logs = WC_Admin_Status::scan_log_files ();
372
+ $ latest_file_date = 0 ;
373
+
374
+ foreach ( $ logs as $ log_key => $ log_file ) {
375
+ if ( ! preg_match ( '/ ' . $ log_prefix . '\-[0-9a-f]{32}\-log/ ' , $ log_key ) ) {
376
+ continue ;
375
377
}
376
378
377
- if ( null !== $ file ) {
378
- $ complete_log = file ( $ file );
379
- $ data ->key = $ key ;
380
- $ data ->file = $ file ;
381
- $ data ->tail = array_slice ( $ complete_log , -10 );
379
+ $ log_file_path = WC_LOG_DIR . $ log_file ;
380
+ $ file_date = filemtime ( $ log_file_path );
381
+
382
+ if ( $ latest_file_date < $ file_date ) {
383
+ $ latest_file_date = $ file_date ;
384
+ $ data ->file = $ log_file_path ;
385
+ $ data ->key = $ log_key ;
382
386
}
383
387
}
384
388
389
+ if ( null !== $ data ->file ) {
390
+ $ complete_log = file ( $ data ->file );
391
+ $ data ->tail = array_slice ( $ complete_log , -10 );
392
+ }
393
+
385
394
return $ data ;
386
395
}
387
396
388
- protected function get_debug_items () {
389
- $ debug_items = array ();
397
+ protected function add_log_view ( $ title , $ feature = '' ) {
398
+ // add connect log tail
399
+ $ log_data = $ this ->get_debug_log_data ( $ feature );
400
+ $ line_count = count ( $ log_data ->tail );
390
401
391
- // add debug on/off boolean
392
- $ debug_items [] = (object ) array (
393
- 'key ' => 'wcc_debug_on ' ,
394
- 'title ' => 'Debug Logging ' ,
395
- 'type ' => 'boolean ' ,
396
- 'true_text ' => __ ( 'Enabled ' , 'woocommerce-services ' ),
397
- 'false_text ' => __ ( 'Disabled ' , 'woocommerce-services ' ),
398
- 'description ' => '' ,
399
- 'value ' => $ this ->logger ->is_debug_enabled (),
400
- 'save_on_toggle ' => true
401
- );
402
+ if ( $ line_count < 1 ) {
402
403
403
- // add connect log tail
404
- $ log_data = $ this ->get_debug_log_data ();
405
- $ log_tail_line_count = count ( $ log_data ->tail );
406
- if ( $ log_tail_line_count < 1 ) {
407
404
$ description = '' ;
408
- $ log_tail = __ ( 'Log is empty ' , 'woocommerce-services ' );
405
+ $ log_tail = __ ( 'Log is empty ' , 'woocommerce-services ' );
406
+
409
407
} else {
408
+
410
409
$ url = add_query_arg (
411
410
array (
412
- 'page ' => 'wc-status ' ,
413
- 'tab ' => 'logs ' ,
411
+ 'page ' => 'wc-status ' ,
412
+ 'tab ' => 'logs ' ,
414
413
'log_file ' => $ log_data ->key
415
414
),
416
415
admin_url ( 'admin.php ' )
417
416
);
417
+
418
418
$ description = sprintf (
419
419
wp_kses (
420
420
__ ( 'Last %d entries <a href="%s">Show full log</a> ' , 'woocommerce-services ' ),
421
421
array ( 'a ' => array ( 'href ' => array () ) ) ),
422
- $ log_tail_line_count ,
422
+ $ line_count ,
423
423
esc_url ( $ url )
424
424
);
425
+
425
426
$ log_tail = implode ( $ log_data ->tail , '' );
427
+
426
428
}
427
429
428
- $ debug_items [] = (object ) array (
429
- 'key ' => 'wcc_debug_log_tail ' ,
430
- 'title ' => __ ( ' Debug Log ' , ' woocommerce-services ' ) ,
431
- 'type ' => 'textarea ' ,
430
+ return (object ) array (
431
+ 'key ' => 'wcc_ ' . $ feature . ' _log_tail ' ,
432
+ 'title ' => $ title ,
433
+ 'type ' => 'textarea ' ,
432
434
'description ' => $ description ,
433
- 'readonly ' => true ,
434
- 'value ' => $ log_tail
435
+ 'readonly ' => true ,
436
+ 'value ' => $ log_tail ,
437
+ );
438
+ }
439
+
440
+ protected function get_debug_items () {
441
+ $ debug_items = array ();
442
+
443
+ // add logging on/off boolean
444
+ $ debug_items [] = (object ) array (
445
+ 'key ' => 'wcc_logging_on ' ,
446
+ 'title ' => 'Logging ' ,
447
+ 'type ' => 'boolean ' ,
448
+ 'true_text ' => __ ( 'Enabled ' , 'woocommerce-services ' ),
449
+ 'false_text ' => __ ( 'Disabled ' , 'woocommerce-services ' ),
450
+ 'description ' => __ ( 'Write diagnostic messages to log files. Helpful when contacting support. ' , 'woocommerce-services ' ),
451
+ 'value ' => $ this ->logger ->is_logging_enabled (),
452
+ 'save_on_toggle ' => true ,
435
453
);
436
454
455
+ // add debug on/off boolean
456
+ $ debug_items [] = (object ) array (
457
+ 'key ' => 'wcc_debug_on ' ,
458
+ 'title ' => 'Debug ' ,
459
+ 'type ' => 'boolean ' ,
460
+ 'true_text ' => __ ( 'Enabled ' , 'woocommerce-services ' ),
461
+ 'false_text ' => __ ( 'Disabled ' , 'woocommerce-services ' ),
462
+ 'description ' => __ ( 'Display troubleshooting information on the Cart and Checkout pages. ' , 'woocommerce-services ' ),
463
+ 'value ' => $ this ->logger ->is_debug_enabled (),
464
+ 'save_on_toggle ' => true ,
465
+ );
466
+
467
+ $ debug_items [] = $ this ->add_log_view ( __ ( 'Shipping Log ' , 'woocommerce-services ' ), 'shipping ' );
468
+ $ debug_items [] = $ this ->add_log_view ( __ ( 'Taxes Log ' , 'woocommerce-services ' ), 'taxes ' );
469
+ $ debug_items [] = $ this ->add_log_view ( __ ( 'Other Log ' , 'woocommerce-services ' ) );
470
+
437
471
return $ debug_items ;
438
472
}
439
473
0 commit comments