cl01/wp-content/plugins/nicen-localize-image/class/log.php
2025-02-24 12:39:24 +08:00

78 lines
1.4 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @author 友人a
* @date 2022/8/27
* 错误日志类
*/
class Nicen_Log {
private static $self;
private $option = 'nicen_plugin_error_log';
private $record_log; //是否需要记录日志
private $logs;
private function __construct() {
add_option( $this->option );//初始化选项
$this->logs = get_option( $this->option );
$this->record_log = get_option( 'nicen_make_plugin_record_log' );
}
/**
* 获取单例
* */
public static function getInstance() {
/*如果实例不存在*/
if ( ! self::$self ) {
self::$self = new self();
}
return self::$self;
}
/**
* 新增一条日志
*
* @param log操作之后的结果
*
* @return array
*/
public function add( $log ) {
if ( ! $this->record_log ) {
return $log;
}
$now = date( "Y-m-d H:i:s", time() );
/**
* 判断结果
* */
if ( $log['code'] ) {
$this->logs .= $now . '' . '本地化成功,' . $log['result'] . "\n";
} else {
$this->logs .= $now . '' . '本地化失败,' . $log['result'] . "\n";
}
update_option( $this->option, $this->logs );
return $log;
}
/**
* @return false|mixed|null
*/
public function get_logs() {
return $this->logs;
}
/**
* 清空日志
* */
public function clear() {
update_option( $this->option, "" );
}
}