40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* 日志封装:使用 WooCommerce 的 WC_Logger
|
|
* - 提供 info / warning / error 三个级别的简洁封装
|
|
* - 统一设置 source = 'yoone-subscriptions',便于在日志中筛选来源
|
|
*/
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Yoone_Subscriptions_Logger {
|
|
/** @var WC_Logger */
|
|
protected static $logger = null;
|
|
|
|
protected static function logger() {
|
|
if (! self::$logger) self::$logger = wc_get_logger();
|
|
return self::$logger;
|
|
}
|
|
|
|
/**
|
|
* 记录信息
|
|
* @param string $message
|
|
* @param array $context
|
|
*/
|
|
public static function info($message, $context = array()) {
|
|
self::logger()->info($message, array('source' => 'yoone-subscriptions') + $context);
|
|
}
|
|
|
|
/**
|
|
* 记录警告
|
|
*/
|
|
public static function warning($message, $context = array()) {
|
|
self::logger()->warning($message, array('source' => 'yoone-subscriptions') + $context);
|
|
}
|
|
|
|
/**
|
|
* 记录错误
|
|
*/
|
|
public static function error($message, $context = array()) {
|
|
self::logger()->error($message, array('source' => 'yoone-subscriptions') + $context);
|
|
}
|
|
} |