Skip to content

Instantly share code, notes, and snippets.

@mrmu
Last active April 28, 2023 09:06
Show Gist options
  • Save mrmu/ab87723d54f720a6d603eeafa9660522 to your computer and use it in GitHub Desktop.
Save mrmu/ab87723d54f720a6d603eeafa9660522 to your computer and use it in GitHub Desktop.
使用 woocommerce 內建的 wc logger,將 debug 用的 log 記錄到後台 WooCommerce / 狀態 / 記錄 裡。
<?php
/*
* arg:
* $msg: 要紀錄的內容,可用 string/array
* $source_name: 此 log 的別名,方便於後台辨識
*/
function my_wc_log($msg, $source_name) {
if (function_exists('wc_get_logger')) {
$log = wc_get_logger();
$log_context = array( 'source' => $source_name );
if (is_array($msg)) {
$log->alert(wc_print_r( $msg, true ), $log_context);
}else{
$log->log('info', $msg, $log_context);
}
}else{
return false;
}
}
@oberonlai
Copy link

感謝大大分享!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment